let the image sit for a bit
This commit is contained in:
51
main.go
51
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:
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user