|
|
|
@ -4,6 +4,9 @@ import (
|
|
|
|
|
"flag"
|
|
|
|
|
"image"
|
|
|
|
|
"image/color"
|
|
|
|
|
_ "image/jpeg"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
@ -34,6 +37,19 @@ func main() {
|
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
fatal(err)
|
|
|
|
|
|
|
|
|
@ -58,13 +74,20 @@ type Animation struct {
|
|
|
|
|
position image.Point
|
|
|
|
|
dir image.Point
|
|
|
|
|
stroke int
|
|
|
|
|
image image.Image
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewAnimation(sz image.Point) *Animation {
|
|
|
|
|
reader, err := os.Open("mario.jpg")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
mario, _, err := image.Decode(reader)
|
|
|
|
|
return &Animation{
|
|
|
|
|
ctx: gg.NewContext(sz.X, sz.Y),
|
|
|
|
|
dir: image.Point{1, 1},
|
|
|
|
|
stroke: 5,
|
|
|
|
|
image: mario,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -74,8 +97,9 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|
|
a.ctx.Clear()
|
|
|
|
|
|
|
|
|
|
a.ctx.DrawCircle(float64(a.position.X), float64(a.position.Y), float64(a.stroke))
|
|
|
|
|
a.ctx.SetColor(color.RGBA{0, 255, 0, 255})
|
|
|
|
|
a.ctx.DrawImage(a.image, a.position.X, a.position.Y)
|
|
|
|
|
//a.ctx.DrawCircle(float64(a.position.X), float64(a.position.Y), float64(a.stroke))
|
|
|
|
|
//a.ctx.SetColor(color.RGBA{0, 255, 0, 255})
|
|
|
|
|
a.ctx.Fill()
|
|
|
|
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
|
|
|
|
}
|
|
|
|
|