From 953cb76ee5fc731f0251da37ffe257a2ddb0b15a Mon Sep 17 00:00:00 2001 From: nathan wagner Date: Mon, 1 Aug 2022 18:18:05 +0000 Subject: [PATCH] saving --- Dockerfile | 1 + main.go | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2dca95c..53b7d0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN go mod tidy RUN go build . RUN mkdir -p /usr/src/app/work/ RUN cp /usr/src/app/rgb/rgb /usr/src/app/work/rgb +RUN cp /usr/src/app/rgb/mario* /usr/src/app/work/ #FROM alpine:latest diff --git a/main.go b/main.go index 152a7fd..0183bdd 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "time" rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix" + "github.com/disintegration/imaging" "github.com/fogleman/gg" ) @@ -37,7 +38,7 @@ func main() { config.InverseColors = *inverse_colors config.DisableHardwarePulsing = *disable_hardware_pulsing - bounds := mario.Bounds() + /*bounds := mario.Bounds() var histogram [16][4]int for y := bounds.Min.Y; y < bounds.Max.Y; y++ { for x := bounds.Min.X; x < bounds.Max.X; x++ { @@ -49,7 +50,7 @@ func main() { histogram[b>>12][2]++ histogram[a>>12][3]++ } - } + }*/ m, err := rgbmatrix.NewRGBLedMatrix(config) fatal(err) @@ -73,6 +74,8 @@ type Animation struct { ctx *gg.Context position image.Point dir image.Point + height int + width int stroke int image image.Image } @@ -82,22 +85,24 @@ func NewAnimation(sz image.Point) *Animation { if err != nil { log.Fatal(err) } - mario, _, err := image.Decode(reader) + rawMario, _, err := image.Decode(reader) + mario := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos)) return &Animation{ ctx: gg.NewContext(sz.X, sz.Y), dir: image.Point{1, 1}, - stroke: 5, + height: 8, + width: 8, + stroke: 16, image: mario, } } func (a *Animation) Next() (image.Image, <-chan time.Time, error) { defer a.updatePosition() - a.ctx.SetColor(color.Black) a.ctx.Clear() - - a.ctx.DrawImage(a.image, a.position.X, a.position.Y) + a.ctx.DrawImageAnchored(a.image, a.position.X, a.position.Y, 0.5, 0.5) + //a.image = imaging.FlipH(a.image) //a.ctx.DrawCircle(float64(a.position.X), float64(a.position.Y), float64(a.stroke)) //a.ctx.SetColor(color.RGBA{0, 255, 0, 255}) a.ctx.Fill() @@ -108,15 +113,17 @@ 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() { + if a.position.Y+a.height > a.ctx.Height() { a.dir.Y = -1 - } else if a.position.Y-a.stroke < 0 { + } else if a.position.Y-a.height < 0 { a.dir.Y = 1 } - if a.position.X+a.stroke > a.ctx.Width() { + if a.position.X+a.width > a.ctx.Width() { a.dir.X = -1 - } else if a.position.X-a.stroke < 0 { + a.image = imaging.FlipH(a.image) + } else if a.position.X-a.width < 0 { a.dir.X = 1 + a.image = imaging.FlipH(a.image) } }