diff --git a/main.go b/main.go index 2f154f5..ad09709 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 } @@ -140,6 +141,12 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation { } } +func appendImage(img string, a *Animation) { + baseImage, _ := b64.StdEncoding.DecodeString(img) + bigImage, _, _ := image.Decode(bytes.NewReader(baseImage)) + a.image = append(a.image, imaging.Resize(bigImage, 32, 32, imaging.Lanczos)) +} + // what happens each frame, at an interval of 50 milliseconds func (a *Animation) Next() (image.Image, <-chan time.Time, error) { incoming := incomingImage{} @@ -168,10 +175,7 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) { a.msg = string(msg.Payload()) a.ctx.DrawString(a.msg, 5, 9) } else { - baseImage, _ := b64.StdEncoding.DecodeString(incoming.Image) - bigImage, _, _ := image.Decode(bytes.NewReader(baseImage)) - a.image = append(a.image, imaging.Resize(bigImage, 32, 32, imaging.Lanczos)) - a.ctx.DrawImageAnchored(a.image[2], 0, 0, 0, 0) + go appendImage(incoming.Image, a) } default: }