|
|
@ -19,6 +19,9 @@ import (
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* contents of struct mostly don't matter for toolkit.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
type Animation struct {
|
|
|
|
type Animation struct {
|
|
|
|
ctx *gg.Context
|
|
|
|
ctx *gg.Context
|
|
|
|
position image.Point
|
|
|
|
position image.Point
|
|
|
@ -56,19 +59,7 @@ func main() {
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
setupMQTT()
|
|
|
|
setupMQTT()
|
|
|
|
/*bounds := mario.Bounds()
|
|
|
|
|
|
|
|
var histogram [16][4]int
|
|
|
|
|
|
|
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
|
|
|
|
|
|
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
|
|
|
|
|
|
|
r, g, b, a := mario.At(x, y).RGBA()
|
|
|
|
|
|
|
|
// A color's RGBA method returns values in the range [0, 65535].
|
|
|
|
|
|
|
|
// Shifting by 12 reduces this to the range [0, 15].
|
|
|
|
|
|
|
|
histogram[r>>12][0]++
|
|
|
|
|
|
|
|
histogram[g>>12][1]++
|
|
|
|
|
|
|
|
histogram[b>>12][2]++
|
|
|
|
|
|
|
|
histogram[a>>12][3]++
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
fatal(err)
|
|
|
|
fatal(err)
|
|
|
|
mqMessages := make(chan mqtt.Message)
|
|
|
|
mqMessages := make(chan mqtt.Message)
|
|
|
@ -108,7 +99,9 @@ func listener(mqMessages chan mqtt.Message) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//animator is a wrapping function for go routine that can receive an mq channel
|
|
|
|
func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) {
|
|
|
|
func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) {
|
|
|
|
|
|
|
|
//Playanimation comes from the toolkit, all it takes is an animation struct
|
|
|
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}, mqMessages))
|
|
|
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}, mqMessages))
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -132,6 +125,7 @@ func fatal(err error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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 {
|
|
|
|
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|
|
|
reader, err := os.Open("marioUp.png")
|
|
|
|
reader, err := os.Open("marioUp.png")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -162,6 +156,7 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// what happens each frame, at an interval of 50 milliseconds
|
|
|
|
func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
defer a.updatePosition()
|
|
|
|
defer a.updatePosition()
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|