Files
python-editor/workspace/code/panel16_utils.py
jimmy e4c811f51d Expand browser editor runtime and LED simulation workflows.
Add Docker deployment support, richer Selenium/LED pattern tests, in-browser diagnostics, responsive UI improvements, and 16x16 panel simulation tooling to speed iteration and hardware-style prototyping.

Made-with: Cursor
2026-05-01 20:24:05 +12:00

27 lines
549 B
Python

"""Helpers for 16x16 serpentine NeoPixel panel animations.
Mapping matches the simulator's 16x16 mode:
- first LED at top-right
- row 0 goes right -> left
- row 1 goes left -> right
"""
from __future__ import annotations
PANEL_W = 16
PANEL_H = 16
def xy_to_index(x: int, y: int, width: int = PANEL_W) -> int:
"""Map panel coordinate (x, y) to LED index."""
x = int(x)
y = int(y)
if y % 2 == 0:
return y * width + (width - 1 - x)
return y * width + x
def clamp8(v: int) -> int:
return max(0, min(255, int(v)))