saving
This commit is contained in:
@@ -7,6 +7,7 @@ RUN go mod tidy
|
|||||||
RUN go build .
|
RUN go build .
|
||||||
RUN mkdir -p /usr/src/app/work/
|
RUN mkdir -p /usr/src/app/work/
|
||||||
RUN cp /usr/src/app/rgb/rgb /usr/src/app/work/rgb
|
RUN cp /usr/src/app/rgb/rgb /usr/src/app/work/rgb
|
||||||
|
RUN cp /usr/src/app/rgb/mario* /usr/src/app/work/
|
||||||
|
|
||||||
#FROM alpine:latest
|
#FROM alpine:latest
|
||||||
|
|
||||||
|
|||||||
29
main.go
29
main.go
@@ -10,6 +10,7 @@ import (
|
|||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ func main() {
|
|||||||
config.InverseColors = *inverse_colors
|
config.InverseColors = *inverse_colors
|
||||||
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
||||||
|
|
||||||
bounds := mario.Bounds()
|
/*bounds := mario.Bounds()
|
||||||
var histogram [16][4]int
|
var histogram [16][4]int
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||||
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||||
@@ -49,7 +50,7 @@ func main() {
|
|||||||
histogram[b>>12][2]++
|
histogram[b>>12][2]++
|
||||||
histogram[a>>12][3]++
|
histogram[a>>12][3]++
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|
||||||
@@ -73,6 +74,8 @@ 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
|
image image.Image
|
||||||
}
|
}
|
||||||
@@ -82,22 +85,24 @@ func NewAnimation(sz image.Point) *Animation {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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{
|
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,
|
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.DrawImage(a.image, a.position.X, a.position.Y)
|
//a.image = imaging.FlipH(a.image)
|
||||||
//a.ctx.DrawCircle(float64(a.position.X), float64(a.position.Y), float64(a.stroke))
|
//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.SetColor(color.RGBA{0, 255, 0, 255})
|
||||||
a.ctx.Fill()
|
a.ctx.Fill()
|
||||||
@@ -108,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user