diff --git a/animateDoorbell.go b/animateDoorbell.go index 9cdce38..4b20c75 100644 --- a/animateDoorbell.go +++ b/animateDoorbell.go @@ -6,18 +6,17 @@ import ( "image" "github.com/disintegration/imaging" + "github.com/fogleman/gg" ) type Doorbell struct { image image.Image } -func (a *Animation) clearDoorbell() { - var door Doorbell - a.doorbell = door -} func loadImage(imgType string, img string, a *Animation) { baseImage, _ := b64.StdEncoding.DecodeString(img) bigImage, _, _ := image.Decode(bytes.NewReader(baseImage)) a.doorbell.image = imaging.Resize(bigImage, 64, 64, imaging.Lanczos) + a.ctx.Push() + a.ctx = gg.NewContext(64, 128) } diff --git a/animationMario.go b/animationMario.go index b7a9f9a..2b574a3 100644 --- a/animationMario.go +++ b/animationMario.go @@ -39,8 +39,7 @@ func initialMap() map[string]image.Image { // initializes the struct for the an play animation function, this could all be dumped into function that's wrapping go routine if I wanted -// what happens each frame, at an interval of 50 milliseconds - +// this assumes mario context is up func (a *Animation) animateMario() { defer a.updateMarioPosition() a.ctx.SetColor(color.Black) diff --git a/board.go b/board.go index 031c847..1b5ed59 100644 --- a/board.go +++ b/board.go @@ -46,17 +46,18 @@ func animate(sz image.Point, mqMessages chan mqtt.Message) *Animation { } func (a *Animation) Next() (image.Image, <-chan time.Time, error) { var incoming incomingMessage - - a.animateMario() - if a.doorbell != (Doorbell{}) { + switch { + case a.doorbell != (Doorbell{}): if a.countDown > 0 { a.ctx.DrawImageAnchored(a.doorbell.image, 0, 0, 0, 0) a.countDown -= 50 } else { - //a.image = a.image[:len(a.image)-1] a.doorbell = Doorbell{} a.countDown = 5000 } + default: + a.ctx.Pop() + a.animateMario() } a.ctx.SetColor(color.White) select {