#!/usr/bin/env python3 """Plasma field.""" from __future__ import annotations import math from leds.colors import hsv_to_rgb from leds.pattern import Pattern, run_cli, set_pixel, size class Plasma(Pattern): id = "plasma" label = "Plasma" fps = 25 def draw(self, surface, t, params): w, h = size(surface) phase = t * self.fps * 0.08 for y in range(h): for x in range(w): v = ( math.sin(x * 0.15 + phase) + math.sin(y * 0.2 - phase * 1.3) + math.sin((x + y) * 0.1 + phase * 0.7) ) / 3.0 set_pixel(surface, x, y, hsv_to_rgb((v + 1) / 2, 1.0, 1.0)) if __name__ == "__main__": run_cli(Plasma)