implement eye logic
confusedbread confuseddbread@gmail.com
Fri, 20 Mar 2026 10:11:40 +0100
1 files changed,
50 insertions(+),
9 deletions(-)
jump to
M
main.go
→
main.go
@@ -3,11 +3,23 @@
import ( "image/color" "machine" + "math" "tinygo.org/x/drivers/ws2812" ) const ledCount = 512 + +type visorConfig struct { + screenWidth int + screenHeight int + spacingOuter int + spacingTop int + eyeWidth int + eyeHeight int + borderWidth int // 0 = full infil + eyeColor color.RGBA +} func unfuckMatrix(matrix []color.RGBA) []color.RGBA { lookup := []int{@@ -36,6 +48,34 @@ }
return out } +func eyes(canvas []color.RGBA, config visorConfig) []color.RGBA { + for i := range canvas { + x := i % 32 + y := int(math.Floor(float64(i) / 32)) + + if y > config.spacingTop && y < config.spacingTop+config.eyeHeight { + if x > config.spacingOuter && x < config.spacingOuter+config.eyeWidth { + canvas[i] = config.eyeColor + } + if x > config.screenWidth-(config.spacingOuter+config.eyeWidth) && x < config.screenWidth-config.spacingOuter { + canvas[i] = config.eyeColor + } + } + } + + if config.borderWidth > 0 { + infilConfig := config + infilConfig.eyeHeight -= config.borderWidth * 2 + infilConfig.eyeWidth -= config.borderWidth * 2 + infilConfig.spacingOuter += config.borderWidth + infilConfig.spacingTop += config.borderWidth + infilConfig.borderWidth = 0 + infilConfig.eyeColor = color.RGBA{R: 0, G: 0, B: 0} + return eyes(canvas, infilConfig) + } + return unfuckMatrix(canvas) +} + func main() { var pin machine.Pin pin = 13@@ -44,14 +84,15 @@
device := ws2812.NewWS2812(pin) leds := make([]color.RGBA, ledCount) - for i := range leds { - if i < 120 { - leds[i] = color.RGBA{ - R: 0, - G: 2, - B: 0, - } - } + config := visorConfig{ + screenWidth: 32, + screenHeight: 16, + spacingOuter: 6, + spacingTop: 2, + eyeWidth: 6, + eyeHeight: 10, + borderWidth: 1, + eyeColor: color.RGBA{R: 2, G: 0, B: 2}, } - device.WriteColors(unfuckMatrix(leds)) + device.WriteColors(eyes(leds, config)) }