changing docker pattern, and default app
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
from registry.local/rgbarm64lib:latest
|
from registry.local/rgbarm64lib:latest as builder
|
||||||
|
|
||||||
workdir /usr/src/app/work
|
workdir /usr/src/app/work
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN go mod tidy
|
RUN go mod tidy
|
||||||
|
|
||||||
RUN go build .
|
RUN go build .
|
||||||
|
|
||||||
|
FROM ALPINE:latest
|
||||||
|
|
||||||
|
COPY --from=builder /usr/src/app/work/rgb /rgb
|
||||||
|
|||||||
63
main.go
63
main.go
@@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"image"
|
||||||
"image/color"
|
"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 (
|
var (
|
||||||
@@ -35,17 +37,10 @@ func main() {
|
|||||||
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|
||||||
c := rgbmatrix.NewCanvas(m)
|
tk := rgbmatrix.NewToolKit(m)
|
||||||
defer c.Close()
|
defer tk.Close()
|
||||||
|
|
||||||
bounds := c.Bounds()
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}))
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -57,3 +52,47 @@ func fatal(err error) {
|
|||||||
panic(err)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user