|
|
|
@ -30,7 +30,6 @@ type Animation struct {
|
|
|
|
|
height int
|
|
|
|
|
width int
|
|
|
|
|
stroke int
|
|
|
|
|
image []image.Image
|
|
|
|
|
images map[string]image.Image
|
|
|
|
|
updown string
|
|
|
|
|
mqmsg chan mqtt.Message
|
|
|
|
@ -45,36 +44,36 @@ func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) {
|
|
|
|
|
tk.PlayAnimation(NewAnimation(image.Point{127, 64}, mqMessages))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// initializes the struct for the an play animation function, this could all be dumped into function that's wrapping go routine if I wanted
|
|
|
|
|
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|
|
|
|
imageMap := make(map[string]image.Image)
|
|
|
|
|
reader, err := os.Open("marioUp.png")
|
|
|
|
|
func loadMario(file string) image.Image {
|
|
|
|
|
|
|
|
|
|
reader, err := os.Open(file)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
rawMario, _, err := image.Decode(reader)
|
|
|
|
|
|
|
|
|
|
//marioUp := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
|
|
|
|
marioUp := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
|
|
|
|
imageMap["marioUp"] = marioUp
|
|
|
|
|
reader, err = os.Open("marioDown.png")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
rawMario, _, err = image.Decode(reader)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
mario := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
|
|
|
|
return mario
|
|
|
|
|
}
|
|
|
|
|
//marioDown := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
|
|
|
|
marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
|
|
|
|
imageMap["marioDown"] = marioDown
|
|
|
|
|
|
|
|
|
|
func initialMap() map[string]image.Image {
|
|
|
|
|
imageMap := make(map[string]image.Image)
|
|
|
|
|
imageMap["marioUp"] = loadMario("marioUp.png")
|
|
|
|
|
imageMap["marioDown"] = loadMario("marioDown.png")
|
|
|
|
|
return imageMap
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// initializes the struct for the an play animation function, this could all be dumped into function that's wrapping go routine if I wanted
|
|
|
|
|
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|
|
|
|
return &Animation{
|
|
|
|
|
ctx: gg.NewContext(sz.X, sz.Y),
|
|
|
|
|
dir: image.Point{1, 1},
|
|
|
|
|
height: 8,
|
|
|
|
|
width: 8,
|
|
|
|
|
stroke: 8,
|
|
|
|
|
images: imageMap,
|
|
|
|
|
images: initialMap(),
|
|
|
|
|
updown: "marioUp",
|
|
|
|
|
mqmsg: mqMessages,
|
|
|
|
|
countDown: 5000,
|
|
|
|
@ -100,7 +99,7 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
|
a.countDown -= 50
|
|
|
|
|
} else {
|
|
|
|
|
//a.image = a.image[:len(a.image)-1]
|
|
|
|
|
delete(a.images, "doorbell")
|
|
|
|
|
//delete(a.images, "doorbell")
|
|
|
|
|
a.countDown = 5000
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|