Add a broad set of new pattern modules and matching pattern smoke scripts so the new effects can be validated directly on-device.
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
import random
|
|
import utime
|
|
|
|
|
|
class SparkleTrail:
|
|
def __init__(self, driver):
|
|
self.driver = driver
|
|
|
|
def run(self, preset):
|
|
colors = preset.c if preset.c else [(120, 120, 255)]
|
|
density = max(1, int(preset.n1) if int(preset.n1) > 0 else 24)
|
|
decay = max(1, min(255, int(preset.n2) if int(preset.n2) > 0 else 210))
|
|
last = utime.ticks_ms()
|
|
while True:
|
|
d = max(1, int(preset.d))
|
|
now = utime.ticks_ms()
|
|
if utime.ticks_diff(now, last) >= d:
|
|
for i in range(self.driver.num_leds):
|
|
r,g,b = self.driver.n[i]
|
|
self.driver.n[i] = ((r*decay)//255, (g*decay)//255, (b*decay)//255)
|
|
sparks = max(1, self.driver.num_leds * density // 255)
|
|
for _ in range(sparks):
|
|
idx = random.randint(0, max(0, self.driver.num_leds - 1))
|
|
c = self.driver.apply_brightness(colors[random.randint(0, len(colors)-1)], preset.b)
|
|
self.driver.n[idx] = c
|
|
self.driver.n.write()
|
|
last = utime.ticks_add(last, d)
|
|
if not preset.a:
|
|
yield
|
|
return
|
|
yield
|