|
|
@ -4,9 +4,13 @@ import (
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
|
"image"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"image/color"
|
|
|
|
|
|
|
|
_ "image/jpeg"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -34,6 +38,19 @@ func main() {
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
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)
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
fatal(err)
|
|
|
|
fatal(err)
|
|
|
|
|
|
|
|
|
|
|
@ -57,25 +74,37 @@ type Animation struct {
|
|
|
|
ctx *gg.Context
|
|
|
|
ctx *gg.Context
|
|
|
|
position image.Point
|
|
|
|
position image.Point
|
|
|
|
dir image.Point
|
|
|
|
dir image.Point
|
|
|
|
|
|
|
|
height int
|
|
|
|
|
|
|
|
width int
|
|
|
|
stroke int
|
|
|
|
stroke int
|
|
|
|
|
|
|
|
image image.Image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewAnimation(sz image.Point) *Animation {
|
|
|
|
func NewAnimation(sz image.Point) *Animation {
|
|
|
|
|
|
|
|
reader, err := os.Open("mario.jpg")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rawMario, _, err := image.Decode(reader)
|
|
|
|
|
|
|
|
mario := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
|
|
|
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},
|
|
|
|
stroke: 5,
|
|
|
|
height: 8,
|
|
|
|
|
|
|
|
width: 8,
|
|
|
|
|
|
|
|
stroke: 16,
|
|
|
|
|
|
|
|
image: mario,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
a.ctx.Clear()
|
|
|
|
a.ctx.Clear()
|
|
|
|
|
|
|
|
a.ctx.DrawImageAnchored(a.image, a.position.X, a.position.Y, 0.5, 0.5)
|
|
|
|
a.ctx.DrawCircle(float64(a.position.X), float64(a.position.Y), float64(a.stroke))
|
|
|
|
//a.image = imaging.FlipH(a.image)
|
|
|
|
a.ctx.SetColor(color.RGBA{0, 255, 0, 255})
|
|
|
|
//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()
|
|
|
|
a.ctx.Fill()
|
|
|
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
|
|
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -84,15 +113,17 @@ func (a *Animation) updatePosition() {
|
|
|
|
a.position.X += 1 * a.dir.X
|
|
|
|
a.position.X += 1 * a.dir.X
|
|
|
|
a.position.Y += 1 * a.dir.Y
|
|
|
|
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
|
|
|
|
a.dir.Y = -1
|
|
|
|
} else if a.position.Y-a.stroke < 0 {
|
|
|
|
} else if a.position.Y-a.height < 0 {
|
|
|
|
a.dir.Y = 1
|
|
|
|
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
|
|
|
|
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.dir.X = 1
|
|
|
|
|
|
|
|
a.image = imaging.FlipH(a.image)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|