From 48bf7932a0ed8bd384ff6e6b6fa717b48f593fa2 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 15 Jun 2023 03:26:37 +0000 Subject: [PATCH] let the image sit for a bit --- main.go | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index c09aed6..f0d2f85 100644 --- a/main.go +++ b/main.go @@ -29,16 +29,17 @@ type incomingImage struct { } type Animation struct { - ctx *gg.Context - position image.Point - dir image.Point - height int - width int - stroke int - image []image.Image - updown int - mqmsg chan mqtt.Message - msg string + ctx *gg.Context + position image.Point + dir image.Point + height int + width int + stroke int + image []image.Image + updown int + mqmsg chan mqtt.Message + msg string + countDown int } //flags from cmd line @@ -127,14 +128,15 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation { marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos) images := []image.Image{marioUp, marioDown} return &Animation{ - ctx: gg.NewContext(sz.X, sz.Y), - dir: image.Point{1, 1}, - height: 8, - width: 8, - stroke: 8, - image: images, - updown: 0, - mqmsg: mqMessages, + ctx: gg.NewContext(sz.X, sz.Y), + dir: image.Point{1, 1}, + height: 8, + width: 8, + stroke: 8, + image: images, + updown: 0, + mqmsg: mqMessages, + countDown: 5000, } } @@ -149,6 +151,15 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) { } else { a.ctx.DrawImageAnchored(imaging.FlipH(a.image[a.updown]), a.position.X, a.position.Y, 0.5, 0.5) } + if a.image[3] != nil { + if a.countDown > 0 { + a.ctx.DrawImageAnchored(a.image[3], 0, 0, 0, 0) + a.countDown -= 50 + } else { + a.image[3] = nil + a.countDown = 5000 + } + } a.ctx.SetColor(color.White) select { case msg := <-a.mqmsg: @@ -159,8 +170,8 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) { } else { baseImage, _ := b64.StdEncoding.DecodeString(incoming.Image) bigImage, _, _ := image.Decode(bytes.NewReader(baseImage)) - littleImage := imaging.Resize(bigImage, 32, 32, imaging.Lanczos) - a.ctx.DrawImageAnchored(littleImage, 0, 0, 0, 0) + a.image[3] = imaging.Resize(bigImage, 32, 32, imaging.Lanczos) + a.ctx.DrawImageAnchored(a.image[3], 0, 0, 0, 0) } default: }