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:
23
lightsync/animations/solid_color.py
Normal file
23
lightsync/animations/solid_color.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""Solid color animation — all LEDs the same color at all times."""
|
||||
from lightsync.animations.base import AnimationBase
|
||||
|
||||
|
||||
class SolidColorAnimation(AnimationBase):
|
||||
"""Time-independent: all LEDs show a single solid color."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
color: tuple[int, int, int] = (255, 255, 255),
|
||||
white: int = 0,
|
||||
) -> None:
|
||||
self.color = tuple(color) # type: ignore[arg-type]
|
||||
self.white = white
|
||||
|
||||
def render(self, t: float, led_count: int) -> list[tuple]:
|
||||
return [self.color] * led_count
|
||||
|
||||
@classmethod
|
||||
def from_params(cls, params: dict) -> "SolidColorAnimation":
|
||||
color = tuple(params.get("color", [255, 255, 255]))
|
||||
white = params.get("white", 0)
|
||||
return cls(color=color, white=white) # type: ignore[arg-type]
|
||||
Reference in New Issue
Block a user