|
|
|
@ -2,10 +2,12 @@ package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"image"
|
|
|
|
|
"image/color"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
|
rgbmatrix "github.com/mcuadros/go-rpi-rgb-led-matrix"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
@ -35,17 +37,10 @@ func main() {
|
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
|
fatal(err)
|
|
|
|
|
|
|
|
|
|
c := rgbmatrix.NewCanvas(m)
|
|
|
|
|
defer c.Close()
|
|
|
|
|
tk := rgbmatrix.NewToolKit(m)
|
|
|
|
|
defer tk.Close()
|
|
|
|
|
|
|
|
|
|
bounds := c.Bounds()
|
|
|
|
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
|
|
|
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
|
|
|
|
fmt.Println("x", x, "y", y)
|
|
|
|
|
c.Set(x, y, color.RGBA{255, 0, 0, 255})
|
|
|
|
|
c.Render()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
@ -57,3 +52,47 @@ func fatal(err error) {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Animation struct {
|
|
|
|
|
ctx *gg.Context
|
|
|
|
|
position image.Point
|
|
|
|
|
dir image.Point
|
|
|
|
|
stroke int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewAnimation(sz image.Point) *Animation {
|
|
|
|
|
return &Animation{
|
|
|
|
|
ctx: gg.NewContext(sz.X, sz.Y),
|
|
|
|
|
dir: image.Point{1, 1},
|
|
|
|
|
stroke: 5,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
|
defer a.updatePosition()
|
|
|
|
|
|
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|
|
a.ctx.Clear()
|
|
|
|
|
|
|
|
|
|
a.ctx.DrawCircle(float64(a.position.X), float64(a.position.Y), float64(a.stroke))
|
|
|
|
|
a.ctx.SetColor(color.RGBA{255, 0, 0, 255})
|
|
|
|
|
a.ctx.Fill()
|
|
|
|
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *Animation) updatePosition() {
|
|
|
|
|
a.position.X += 1 * a.dir.X
|
|
|
|
|
a.position.Y += 1 * a.dir.Y
|
|
|
|
|
|
|
|
|
|
if a.position.Y+a.stroke > a.ctx.Height() {
|
|
|
|
|
a.dir.Y = -1
|
|
|
|
|
} else if a.position.Y-a.stroke < 0 {
|
|
|
|
|
a.dir.Y = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if a.position.X+a.stroke > a.ctx.Width() {
|
|
|
|
|
a.dir.X = -1
|
|
|
|
|
} else if a.position.X-a.stroke < 0 {
|
|
|
|
|
a.dir.X = 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|