"""Strobe animation — rapid on/off flashing.""" from lightsync.animations.base import AnimationBase class StrobeAnimation(AnimationBase): """Rapid on/off flashing at configurable frequency and duty cycle. speed=0.5 -> ~10.5 Hz. duty_cycle=0.1 means 10% on, 90% off. """ def __init__( self, color: tuple[int, int, int] = (255, 255, 255), speed: float = 0.5, duty_cycle: float = 0.1, white: int = 0, ) -> None: self.color = tuple(color) # type: ignore[arg-type] self.speed = speed self.duty_cycle = duty_cycle self.white = white def render(self, t: float, led_count: int) -> list[tuple]: # Frequency: 1-20 Hz mapped from speed 0.0-1.0 freq = 1.0 + self.speed * 19.0 phase = (t * freq) % 1.0 if phase < self.duty_cycle: pixel = self.color else: pixel = (0, 0, 0) return [pixel] * led_count @classmethod def from_params(cls, params: dict) -> "StrobeAnimation": return cls( color=tuple(params.get("color", [255, 255, 255])), # type: ignore[arg-type] speed=params.get("speed", 0.5), duty_cycle=params.get("duty_cycle", 0.1), white=params.get("white", 0), )