|
|
|
@ -10,6 +10,7 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -37,7 +38,7 @@ func main() {
|
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
|
|
|
|
|
|
bounds := mario.Bounds()
|
|
|
|
|
/*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++ {
|
|
|
|
@ -49,7 +50,7 @@ func main() {
|
|
|
|
|
histogram[b>>12][2]++
|
|
|
|
|
histogram[a>>12][3]++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
|
fatal(err)
|
|
|
|
|
|
|
|
|
@ -73,6 +74,8 @@ type Animation struct {
|
|
|
|
|
ctx *gg.Context
|
|
|
|
|
position image.Point
|
|
|
|
|
dir image.Point
|
|
|
|
|
height int
|
|
|
|
|
width int
|
|
|
|
|
stroke int
|
|
|
|
|
image image.Image
|
|
|
|
|
}
|
|
|
|
@ -82,22 +85,24 @@ func NewAnimation(sz image.Point) *Animation {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
mario, _, err := image.Decode(reader)
|
|
|
|
|
rawMario, _, err := image.Decode(reader)
|
|
|
|
|
mario := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
|
|
|
|
return &Animation{
|
|
|
|
|
ctx: gg.NewContext(sz.X, sz.Y),
|
|
|
|
|
dir: image.Point{1, 1},
|
|
|
|
|
stroke: 5,
|
|
|
|
|
height: 8,
|
|
|
|
|
width: 8,
|
|
|
|
|
stroke: 16,
|
|
|
|
|
image: mario,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
|
defer a.updatePosition()
|
|
|
|
|
|
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|
|
a.ctx.Clear()
|
|
|
|
|
|
|
|
|
|
a.ctx.DrawImage(a.image, a.position.X, a.position.Y)
|
|
|
|
|
a.ctx.DrawImageAnchored(a.image, a.position.X, a.position.Y, 0.5, 0.5)
|
|
|
|
|
//a.image = imaging.FlipH(a.image)
|
|
|
|
|
//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()
|
|
|
|
@ -108,15 +113,17 @@ func (a *Animation) updatePosition() {
|
|
|
|
|
a.position.X += 1 * a.dir.X
|
|
|
|
|
a.position.Y += 1 * a.dir.Y
|
|
|
|
|
|
|
|
|
|
if a.position.Y+a.stroke > a.ctx.Height() {
|
|
|
|
|
if a.position.Y+a.height > a.ctx.Height() {
|
|
|
|
|
a.dir.Y = -1
|
|
|
|
|
} else if a.position.Y-a.stroke < 0 {
|
|
|
|
|
} else if a.position.Y-a.height < 0 {
|
|
|
|
|
a.dir.Y = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if a.position.X+a.stroke > a.ctx.Width() {
|
|
|
|
|
if a.position.X+a.width > a.ctx.Width() {
|
|
|
|
|
a.dir.X = -1
|
|
|
|
|
} else if a.position.X-a.stroke < 0 {
|
|
|
|
|
a.image = imaging.FlipH(a.image)
|
|
|
|
|
} else if a.position.X-a.width < 0 {
|
|
|
|
|
a.dir.X = 1
|
|
|
|
|
a.image = imaging.FlipH(a.image)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|