From 6a9e7d009c2b17e5cb8a7e0ab8d47ed8c3d4d6e9 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Thu, 11 Jan 2024 23:42:15 +0000 Subject: [PATCH 1/7] moving animations around --- main.go | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 709d684..612d8ae 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,8 @@ type Animation struct { width int stroke int image []image.Image - updown int + images map[string]image.Image + updown string mqmsg chan mqtt.Message msg string @@ -112,6 +113,7 @@ 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 func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation { + imageMap := make(map[string]image.Image) reader, err := os.Open("marioUp.png") if err != nil { log.Fatal(err) @@ -120,7 +122,7 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation { //marioUp := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos)) marioUp := imaging.Resize(rawMario, 16, 16, imaging.Lanczos) - + imageMap["marioUp"] = marioUp reader, err = os.Open("marioDown.png") if err != nil { log.Fatal(err) @@ -128,15 +130,17 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation { rawMario, _, err = image.Decode(reader) //marioDown := imaging.FlipH(imaging.Resize(rawMario, 16, 16, imaging.Lanczos)) marioDown := imaging.Resize(rawMario, 16, 16, imaging.Lanczos) - images := []image.Image{marioUp, marioDown} + imageMap["marioDown"] = marioDown + imageSlice := []image.Image{marioUp, marioDown} return &Animation{ ctx: gg.NewContext(sz.X, sz.Y), dir: image.Point{1, 1}, height: 8, width: 8, stroke: 8, - image: images, - updown: 0, + image: imageSlice, + images: imageMap, + updown: "marioUp", mqmsg: mqMessages, countDown: 5000, } @@ -145,26 +149,20 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation { func appendImage(img string, a *Animation) { baseImage, _ := b64.StdEncoding.DecodeString(img) bigImage, _, _ := image.Decode(bytes.NewReader(baseImage)) - a.image = append(a.image, imaging.Resize(bigImage, 64, 64, imaging.Lanczos)) + a.images["doorbell"] = imaging.Resize(bigImage, 64, 64, imaging.Lanczos) } // what happens each frame, at an interval of 50 milliseconds func (a *Animation) Next() (image.Image, <-chan time.Time, error) { incoming := incomingImage{} - defer a.updatePosition() - 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 { + a.animateMario() + if a.images["doorbell"] != nil { if a.countDown > 0 { a.ctx.DrawImageAnchored(a.image[2], 0, 0, 0, 0) a.countDown -= 50 } else { - a.image = a.image[:len(a.image)-1] + //a.image = a.image[:len(a.image)-1] + delete(a.images, "doorbell") a.countDown = 5000 } } @@ -183,16 +181,27 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) { 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 -func (a *Animation) updatePosition() { +func (a *Animation) updateMarioPosition() { a.position.X += 1 * a.dir.X a.position.Y += 1 * a.dir.Y if a.position.Y+a.height > a.ctx.Height() { a.dir.Y = -1 - a.updown = 0 + a.updown = "marioUp" } else if a.position.Y-a.height < 0 { - a.updown = 1 + a.updown = "marioDown" a.dir.Y = 1 } From 9f78ab3b8d9f7ce44d0968f2349e851783475c75 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2024 00:40:18 +0000 Subject: [PATCH 2/7] Update 'main.go' --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index 612d8ae..e322cf5 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,6 @@ import ( "os/signal" "syscall" "time" - rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix" "github.com/disintegration/imaging" MQTT "github.com/eclipse/paho.mqtt.golang" From 7301b46de9957260fa63bad757562bf3de95aa59 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2024 00:41:23 +0000 Subject: [PATCH 3/7] Update 'main.go' --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index e322cf5..4b4e12f 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,6 @@ import ( ) // contents of struct mostly don't matter for toolkit. - type incomingImage struct { Image string `json:"image"` } From 1d7e41c637a7273de9f626dae51d24feedd8f714 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2024 00:42:19 +0000 Subject: [PATCH 4/7] Update 'Dockerfile' --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d636296..a8bb97f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,3 @@ FROM scratch COPY --from=builder /usr/src/app/rgb/rgb /usr/src/app/work/ COPY --from=builder /usr/src/app/rgb/mari* /usr/src/app/work/ WORKDIR /usr/src/app/work - From 3e43ccd4ee0a0250d1f4ea15759019928986628f Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2024 00:43:45 +0000 Subject: [PATCH 5/7] Add '.gitea/workflows/Build.yaml' --- .gitea/workflows/Build.yaml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .gitea/workflows/Build.yaml diff --git a/.gitea/workflows/Build.yaml b/.gitea/workflows/Build.yaml new file mode 100644 index 0000000..38a6f29 --- /dev/null +++ b/.gitea/workflows/Build.yaml @@ -0,0 +1,37 @@ +name: build only rgb-board +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: + push: + branches: + - "animate-separate" + paths-ignore: + - ".gitea/workflows/**" + +jobs: + build: + runs-on: ubuntu-latest + container: + image: registry.local/catthehacker-home:act-latest + volumes: + - /var/run/user/1000/docker.sock:/var/run/docker.sock + steps: + - uses: actions/checkout@v3 + - name: short-sha + id: short-sha + run: echo "short-sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + driver-opts: | + image=registry.local/buildkit-wagnerca:stable-3-rootless + seccomp=unconfined + apparmor=unconfined + systempaths=unconfined + privileged=false + - run: docker buildx ls + - name: push rgbboard + uses: docker/build-push-action@master + with: + push: false + tags: registry.local/rgbboard:${{ steps.short-sha.outputs.short-sha }} + platforms: linux/arm64,linux/amd64 \ No newline at end of file From a3e2a9b939323ed2f393c981207c92e22492bee1 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2024 00:44:03 +0000 Subject: [PATCH 6/7] Update 'Dockerfile' --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index a8bb97f..d636296 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,3 +11,4 @@ FROM scratch COPY --from=builder /usr/src/app/rgb/rgb /usr/src/app/work/ COPY --from=builder /usr/src/app/rgb/mari* /usr/src/app/work/ WORKDIR /usr/src/app/work + From 806fbe8813efa6784869bfa39d9b1b8fbbdabe69 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2024 01:25:27 +0000 Subject: [PATCH 7/7] Delete '.gitea/workflows/Build.yaml' --- .gitea/workflows/Build.yaml | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 .gitea/workflows/Build.yaml diff --git a/.gitea/workflows/Build.yaml b/.gitea/workflows/Build.yaml deleted file mode 100644 index 38a6f29..0000000 --- a/.gitea/workflows/Build.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: build only rgb-board -run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 -on: - push: - branches: - - "animate-separate" - paths-ignore: - - ".gitea/workflows/**" - -jobs: - build: - runs-on: ubuntu-latest - container: - image: registry.local/catthehacker-home:act-latest - volumes: - - /var/run/user/1000/docker.sock:/var/run/docker.sock - steps: - - uses: actions/checkout@v3 - - name: short-sha - id: short-sha - run: echo "short-sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - driver-opts: | - image=registry.local/buildkit-wagnerca:stable-3-rootless - seccomp=unconfined - apparmor=unconfined - systempaths=unconfined - privileged=false - - run: docker buildx ls - - name: push rgbboard - uses: docker/build-push-action@master - with: - push: false - tags: registry.local/rgbboard:${{ steps.short-sha.outputs.short-sha }} - platforms: linux/arm64,linux/amd64 \ No newline at end of file