"""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), )