feat(03-02): implement animation library — 7 types with registry and factory

- AnimationBase ABC with render(t, led_count) and from_params() contract
- SolidColorAnimation: time-independent uniform fill
- ChaseAnimation: moving lit segment with forward/reverse support
- PulseAnimation: sine-wave breathing effect (speed maps to period)
- RainbowAnimation: HSV hue cycle across strip via colorsys.hsv_to_rgb
- StrobeAnimation: on/off flashing at 1-20 Hz with configurable duty cycle
- ColorWipeAnimation: progressive fill from start or end
- FireAnimation: Fire2012 algorithm with cooling/sparking/heat-to-color mapping
- ANIMATION_REGISTRY + create_animation() factory function
- All 24 tests passing
This commit is contained in:
Claude
2026-04-06 21:47:39 +00:00
parent 920243fcae
commit f4da9564d4
10 changed files with 422 additions and 3 deletions

View File

@@ -0,0 +1,28 @@
"""AnimationBase ABC — all animations implement render() and from_params()."""
from abc import ABC, abstractmethod
class AnimationBase(ABC):
"""Pure animation renderer — no I/O, stateless or state-per-instance.
Each animation computes pixel data from time t and strip length.
No networking, no disk I/O — just math.
"""
@abstractmethod
def render(self, t: float, led_count: int) -> list[tuple]:
"""Render frame at time t (seconds since animation started).
Returns list of (R, G, B) tuples, length == led_count.
All channel values in range 0-255.
"""
...
@classmethod
@abstractmethod
def from_params(cls, params: dict) -> "AnimationBase":
"""Construct from CueModel.params dict.
Missing keys use animation-specific defaults.
"""
...