|
|
@ -29,16 +29,17 @@ type incomingImage struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Animation struct {
|
|
|
|
type Animation struct {
|
|
|
|
ctx *gg.Context
|
|
|
|
ctx *gg.Context
|
|
|
|
position image.Point
|
|
|
|
position image.Point
|
|
|
|
dir image.Point
|
|
|
|
dir image.Point
|
|
|
|
height int
|
|
|
|
height int
|
|
|
|
width int
|
|
|
|
width int
|
|
|
|
stroke int
|
|
|
|
stroke int
|
|
|
|
image []image.Image
|
|
|
|
image []image.Image
|
|
|
|
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
|
|
|
@ -127,14 +128,15 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|
|
|
marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
|
|
|
marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
|
|
|
images := []image.Image{marioUp, marioDown}
|
|
|
|
images := []image.Image{marioUp, marioDown}
|
|
|
|
return &Animation{
|
|
|
|
return &Animation{
|
|
|
|
ctx: gg.NewContext(sz.X, sz.Y),
|
|
|
|
ctx: gg.NewContext(sz.X, sz.Y),
|
|
|
|
dir: image.Point{1, 1},
|
|
|
|
dir: image.Point{1, 1},
|
|
|
|
height: 8,
|
|
|
|
height: 8,
|
|
|
|
width: 8,
|
|
|
|
width: 8,
|
|
|
|
stroke: 8,
|
|
|
|
stroke: 8,
|
|
|
|
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:
|
|
|
|
}
|
|
|
|
}
|
|
|
|