created some handler functions
build rgb-board / build (push) Successful in 1m34s Details

checking what happens if i don't delete image from map
main
Nathan Wagner 10 months ago
parent 41e317452f
commit 970f840140

@ -30,7 +30,6 @@ type Animation struct {
height int height int
width int width int
stroke int stroke int
image []image.Image
images map[string]image.Image images map[string]image.Image
updown string updown string
mqmsg chan mqtt.Message 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)) 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 loadMario(file string) image.Image {
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
imageMap := make(map[string]image.Image)
reader, err := os.Open("marioUp.png")
if err != nil {
log.Fatal(err)
}
rawMario, _, err := image.Decode(reader)
//marioUp := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos)) reader, err := os.Open(file)
marioUp := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
imageMap["marioUp"] = marioUp
reader, err = os.Open("marioDown.png")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
rawMario, _, err = image.Decode(reader) rawMario, _, err := image.Decode(reader)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
//marioDown := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos)) mario := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos) return mario
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{ 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,
images: imageMap, images: initialMap(),
updown: "marioUp", updown: "marioUp",
mqmsg: mqMessages, mqmsg: mqMessages,
countDown: 5000, countDown: 5000,
@ -100,7 +99,7 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
a.countDown -= 50 a.countDown -= 50
} else { } else {
//a.image = a.image[:len(a.image)-1] //a.image = a.image[:len(a.image)-1]
delete(a.images, "doorbell") //delete(a.images, "doorbell")
a.countDown = 5000 a.countDown = 5000
} }
} }

Loading…
Cancel
Save