feat(patterns): add expanded animation pack with smoke tests
Add a broad set of new pattern modules and matching pattern smoke scripts so the new effects can be validated directly on-device.
This commit is contained in:
36
src/patterns/snowfall.py
Normal file
36
src/patterns/snowfall.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import random
|
||||
import utime
|
||||
|
||||
|
||||
class Snowfall:
|
||||
def __init__(self, driver):
|
||||
self.driver = driver
|
||||
|
||||
def run(self, preset):
|
||||
colors = preset.c if preset.c else [(255, 255, 255), (180, 220, 255)]
|
||||
density = max(1, int(preset.n1) if int(preset.n1) > 0 else 20)
|
||||
speed = max(1, int(preset.n2) if int(preset.n2) > 0 else 1)
|
||||
flakes = []
|
||||
last = utime.ticks_ms()
|
||||
while True:
|
||||
d = max(1, int(preset.d))
|
||||
now = utime.ticks_ms()
|
||||
if utime.ticks_diff(now, last) >= d:
|
||||
if random.randint(0, 255) < density:
|
||||
flakes.append([self.driver.num_leds - 1, random.randint(0, len(colors)-1)])
|
||||
for i in range(self.driver.num_leds):
|
||||
self.driver.n[i] = (0, 0, 0)
|
||||
nf = []
|
||||
for pos, ci in flakes:
|
||||
if 0 <= pos < self.driver.num_leds:
|
||||
self.driver.n[pos] = self.driver.apply_brightness(colors[ci], preset.b)
|
||||
pos -= speed
|
||||
if pos >= -1:
|
||||
nf.append([pos, ci])
|
||||
flakes = nf
|
||||
self.driver.n.write()
|
||||
last = utime.ticks_add(last, d)
|
||||
if not preset.a:
|
||||
yield
|
||||
return
|
||||
yield
|
||||
Reference in New Issue
Block a user