Created
October 28, 2019 11:33
-
-
Save aykevl/9ef738601b3827508fc725bcea5928a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a small example (and test) how to use tilegraphics. It displays a | |
// small yellow square on a black background that bounces to both sides of the display. | |
package main | |
import ( | |
"image/color" | |
"time" | |
"github.com/aykevl/go-smartwatch" | |
"github.com/aykevl/tilegraphics" | |
) | |
func main() { | |
watch, _ := smartwatch.Open() | |
engine := tilegraphics.NewEngine(watch) | |
var ( | |
x = int16(30) | |
y = int16(30) | |
width = int16(40) | |
height = int16(40) | |
) | |
screenWidth, _ := watch.Size() | |
rect := engine.NewRectangle(x, y, width, height, color.RGBA{255, 255, 0, 255}) | |
engine.Display() | |
move := int16(2) | |
for { | |
start := time.Now() | |
if x+width >= screenWidth { | |
move = -move | |
} | |
if x <= 0 { | |
move = -move | |
} | |
x += move | |
rect.Move(x, y, width, height) | |
engine.Display() | |
// Sleep for a bit, trying to reach 60fps. | |
elapsed := time.Since(start) | |
sleepTime := time.Second/60 - elapsed | |
if sleepTime > 0 { | |
time.Sleep(sleepTime) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment