Skip to content

Commit

Permalink
fix: anim tests and mfp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 11, 2024
1 parent 67c02d1 commit b385d1f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
33 changes: 33 additions & 0 deletions pkg/anim/anim_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package anim

import (
"testing"
"time"

"github.com/cfoust/cy/pkg/geom"
"github.com/cfoust/cy/pkg/geom/image"
)

// Subject all animations to a few simple smoke tests.
func TestAnims(t *testing.T) {
for name, anim := range Animations {
t.Logf("testing anim %s", name)

// The most common point of failure for animations is failing
// to do adequate bounds checks. This renders every animation
// at a few different sizes to ensure that doesn't happen.
for _, size := range []geom.Size{
geom.Size{},
geom.Size{
R: 5,
C: 5,
},
geom.DEFAULT_SIZE,
} {
instance := anim()
instance.Init(image.New(size))
instance.Update(0)
instance.Update(time.Second)
}
}
}
11 changes: 9 additions & 2 deletions pkg/anim/musicforprogramming/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,16 @@ func (r *MFP) drawVisualizer(delta time.Duration) {
}

func (r *MFP) Update(delta time.Duration) image.Image {
size := r.out.Size()

r.drawBackground(delta)
image.Copy(geom.Vec2{}, r.out, r.bg)

colOffset := 1
rowOffset := 1

for row := 0; row < r.out.Size().R; row++ {
for col := 0; col < geom.Min(r.out.Size().C-1, PANEL_WIDTH+colOffset); col++ {
for row := 0; row < size.R; row++ {
for col := 0; col < geom.Min(size.C-1, PANEL_WIDTH+colOffset); col++ {
r.out[row][col].Char = ' '
}
}
Expand All @@ -404,6 +406,11 @@ func (r *MFP) Update(delta time.Duration) image.Image {
for col := 0; col < PANEL_WIDTH; col++ {
cellRow := visualRow + VISUAL_HEIGHT
cellCol := col + colOffset

if cellRow >= size.R || cellCol >= size.C {
continue
}

r.out[cellRow][cellCol].Char = TRACK_TITLE[(col+titleIndex)%len(TRACK_TITLE)]
r.out[cellRow][cellCol].FG = emu.ANSIColor(8)
}
Expand Down

0 comments on commit b385d1f

Please sign in to comment.