let the image sit for a bit

pull/3/head
nathan 1 year ago
parent 336a5c2bf6
commit 48bf7932a0

@ -39,6 +39,7 @@ type Animation struct {
updown int updown int
mqmsg chan mqtt.Message mqmsg chan mqtt.Message
msg string msg string
countDown int
} }
//flags from cmd line //flags from cmd line
@ -135,6 +136,7 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
image: images, image: images,
updown: 0, updown: 0,
mqmsg: mqMessages, mqmsg: mqMessages,
countDown: 5000,
} }
} }
@ -149,6 +151,15 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
} else { } else {
a.ctx.DrawImageAnchored(imaging.FlipH(a.image[a.updown]), a.position.X, a.position.Y, 0.5, 0.5) 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) a.ctx.SetColor(color.White)
select { select {
case msg := <-a.mqmsg: case msg := <-a.mqmsg:
@ -159,8 +170,8 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
} else { } else {
baseImage, _ := b64.StdEncoding.DecodeString(incoming.Image) baseImage, _ := b64.StdEncoding.DecodeString(incoming.Image)
bigImage, _, _ := image.Decode(bytes.NewReader(baseImage)) bigImage, _, _ := image.Decode(bytes.NewReader(baseImage))
littleImage := imaging.Resize(bigImage, 32, 32, imaging.Lanczos) a.image[3] = imaging.Resize(bigImage, 32, 32, imaging.Lanczos)
a.ctx.DrawImageAnchored(littleImage, 0, 0, 0, 0) a.ctx.DrawImageAnchored(a.image[3], 0, 0, 0, 0)
} }
default: default:
} }

Loading…
Cancel
Save