- 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
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Color wipe animation — progressively fills the strip with color."""
|
|
from lightsync.animations.base import AnimationBase
|
|
|
|
|
|
class ColorWipeAnimation(AnimationBase):
|
|
"""Progressively fills the strip from one end with a single color.
|
|
|
|
At speed=1.0, fills at 60 pixels/second.
|
|
reverse=True fills from the end instead of the start.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
color: tuple[int, int, int] = (255, 255, 255),
|
|
speed: float = 0.5,
|
|
reverse: bool = False,
|
|
white: int = 0,
|
|
) -> None:
|
|
self.color = tuple(color) # type: ignore[arg-type]
|
|
self.speed = speed
|
|
self.reverse = reverse
|
|
self.white = white
|
|
|
|
def render(self, t: float, led_count: int) -> list[tuple]:
|
|
fill_count = min(led_count, int(t * self.speed * 60))
|
|
black = (0, 0, 0)
|
|
|
|
if not self.reverse:
|
|
# Fill from start: first fill_count pixels = color
|
|
pixels = [self.color] * fill_count + [black] * (led_count - fill_count)
|
|
else:
|
|
# Fill from end: last fill_count pixels = color
|
|
pixels = [black] * (led_count - fill_count) + [self.color] * fill_count
|
|
|
|
return pixels
|
|
|
|
@classmethod
|
|
def from_params(cls, params: dict) -> "ColorWipeAnimation":
|
|
return cls(
|
|
color=tuple(params.get("color", [255, 255, 255])), # type: ignore[arg-type]
|
|
speed=params.get("speed", 0.5),
|
|
reverse=params.get("reverse", False),
|
|
white=params.get("white", 0),
|
|
)
|