"""Rainbow animation — full HSV hue cycle across the strip.""" import colorsys from lightsync.animations.base import AnimationBase class RainbowAnimation(AnimationBase): """Hue-shifting rainbow across the entire strip. period=1.0 means one full rainbow cycle fits on the strip. speed controls how fast the hues shift over time. """ def __init__( self, speed: float = 0.5, period: float = 1.0, ) -> None: self.speed = speed self.period = period def render(self, t: float, led_count: int) -> list[tuple]: pixels = [] for i in range(led_count): hue = (i / led_count / self.period + t * self.speed) % 1.0 r_f, g_f, b_f = colorsys.hsv_to_rgb(hue, 1.0, 1.0) pixels.append(( int(r_f * 255), int(g_f * 255), int(b_f * 255), )) return pixels @classmethod def from_params(cls, params: dict) -> "RainbowAnimation": return cls( speed=params.get("speed", 0.5), period=params.get("period", 1.0), )