Compare commits
5 Commits
animate-se
...
50e5422009
| Author | SHA1 | Date | |
|---|---|---|---|
| 50e5422009 | |||
| 60287d91d6 | |||
| 87470bddcb | |||
| db3445e124 | |||
| b001c0f628 |
@@ -27,7 +27,7 @@ jobs:
|
|||||||
seccomp=unconfined
|
seccomp=unconfined
|
||||||
apparmor=unconfined
|
apparmor=unconfined
|
||||||
systempaths=unconfined
|
systempaths=unconfined
|
||||||
privileged=false
|
privileged=false
|
||||||
- run: docker buildx ls
|
- run: docker buildx ls
|
||||||
- name: push rgbboard
|
- name: push rgbboard
|
||||||
uses: docker/build-push-action@master
|
uses: docker/build-push-action@master
|
||||||
|
|||||||
49
main.go
49
main.go
@@ -14,6 +14,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"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/disintegration/imaging"
|
||||||
MQTT "github.com/eclipse/paho.mqtt.golang"
|
MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||||
@@ -22,6 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// contents of struct mostly don't matter for toolkit.
|
// contents of struct mostly don't matter for toolkit.
|
||||||
|
|
||||||
type incomingImage struct {
|
type incomingImage struct {
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
@@ -34,8 +36,7 @@ type Animation struct {
|
|||||||
width int
|
width int
|
||||||
stroke int
|
stroke int
|
||||||
image []image.Image
|
image []image.Image
|
||||||
images map[string]image.Image
|
updown int
|
||||||
updown string
|
|
||||||
mqmsg chan mqtt.Message
|
mqmsg chan mqtt.Message
|
||||||
msg string
|
msg string
|
||||||
|
|
||||||
@@ -111,7 +112,6 @@ 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
|
//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 {
|
||||||
imageMap := make(map[string]image.Image)
|
|
||||||
reader, err := os.Open("marioUp.png")
|
reader, err := os.Open("marioUp.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -120,7 +120,7 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|||||||
|
|
||||||
//marioUp := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
//marioUp := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
||||||
marioUp := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
marioUp := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
||||||
imageMap["marioUp"] = marioUp
|
|
||||||
reader, err = os.Open("marioDown.png")
|
reader, err = os.Open("marioDown.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -128,17 +128,15 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|||||||
rawMario, _, err = image.Decode(reader)
|
rawMario, _, err = image.Decode(reader)
|
||||||
//marioDown := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
//marioDown := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos))
|
||||||
marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos)
|
||||||
imageMap["marioDown"] = marioDown
|
images := []image.Image{marioUp, marioDown}
|
||||||
imageSlice := []image.Image{marioUp, marioDown}
|
|
||||||
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},
|
||||||
height: 8,
|
height: 8,
|
||||||
width: 8,
|
width: 8,
|
||||||
stroke: 8,
|
stroke: 8,
|
||||||
image: imageSlice,
|
image: images,
|
||||||
images: imageMap,
|
updown: 0,
|
||||||
updown: "marioUp",
|
|
||||||
mqmsg: mqMessages,
|
mqmsg: mqMessages,
|
||||||
countDown: 5000,
|
countDown: 5000,
|
||||||
}
|
}
|
||||||
@@ -147,20 +145,26 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|||||||
func appendImage(img string, a *Animation) {
|
func appendImage(img string, a *Animation) {
|
||||||
baseImage, _ := b64.StdEncoding.DecodeString(img)
|
baseImage, _ := b64.StdEncoding.DecodeString(img)
|
||||||
bigImage, _, _ := image.Decode(bytes.NewReader(baseImage))
|
bigImage, _, _ := image.Decode(bytes.NewReader(baseImage))
|
||||||
a.images["doorbell"] = imaging.Resize(bigImage, 64, 64, imaging.Lanczos)
|
a.image = append(a.image, imaging.Resize(bigImage, 64, 64, imaging.Lanczos))
|
||||||
}
|
}
|
||||||
|
|
||||||
// what happens each frame, at an interval of 50 milliseconds
|
// 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) {
|
||||||
incoming := incomingImage{}
|
incoming := incomingImage{}
|
||||||
a.animateMario()
|
defer a.updatePosition()
|
||||||
if a.images["doorbell"] != nil {
|
a.ctx.SetColor(color.Black)
|
||||||
|
a.ctx.Clear()
|
||||||
|
if a.dir.X == 1 {
|
||||||
|
a.ctx.DrawImageAnchored(a.image[a.updown], a.position.X, a.position.Y, 0.5, 0.5)
|
||||||
|
} else {
|
||||||
|
a.ctx.DrawImageAnchored(imaging.FlipH(a.image[a.updown]), a.position.X, a.position.Y, 0.5, 0.5)
|
||||||
|
}
|
||||||
|
if len(a.image) == 3 {
|
||||||
if a.countDown > 0 {
|
if a.countDown > 0 {
|
||||||
a.ctx.DrawImageAnchored(a.image[2], 0, 0, 0, 0)
|
a.ctx.DrawImageAnchored(a.image[2], 0, 0, 0, 0)
|
||||||
a.countDown -= 50
|
a.countDown -= 50
|
||||||
} else {
|
} else {
|
||||||
//a.image = a.image[:len(a.image)-1]
|
a.image = a.image[:len(a.image)-1]
|
||||||
delete(a.images, "doorbell")
|
|
||||||
a.countDown = 5000
|
a.countDown = 5000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,27 +183,16 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|||||||
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Animation) animateMario() {
|
|
||||||
defer a.updateMarioPosition()
|
|
||||||
a.ctx.SetColor(color.Black)
|
|
||||||
a.ctx.Clear()
|
|
||||||
if a.dir.X == 1 {
|
|
||||||
a.ctx.DrawImageAnchored(a.images[a.updown], a.position.X, a.position.Y, 0.5, 0.5)
|
|
||||||
} else {
|
|
||||||
a.ctx.DrawImageAnchored(imaging.FlipH(a.images[a.updown]), a.position.X, a.position.Y, 0.5, 0.5)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//what mario does every frame
|
//what mario does every frame
|
||||||
func (a *Animation) updateMarioPosition() {
|
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.height > a.ctx.Height() {
|
if a.position.Y+a.height > a.ctx.Height() {
|
||||||
a.dir.Y = -1
|
a.dir.Y = -1
|
||||||
a.updown = "marioUp"
|
a.updown = 0
|
||||||
} else if a.position.Y-a.height < 0 {
|
} else if a.position.Y-a.height < 0 {
|
||||||
a.updown = "marioDown"
|
a.updown = 1
|
||||||
a.dir.Y = 1
|
a.dir.Y = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user