Skip to content

Instantly share code, notes, and snippets.

@aykevl
Created October 28, 2019 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aykevl/9ef738601b3827508fc725bcea5928a5 to your computer and use it in GitHub Desktop.
Save aykevl/9ef738601b3827508fc725bcea5928a5 to your computer and use it in GitHub Desktop.
// 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