fix(patterns): use preset background fallback across animations

Align pattern background rendering to use preset.background_or(...) and update pulse/radiate single-step behaviour to preserve visible frames and step progression.
This commit is contained in:
2026-05-09 14:28:05 +12:00
parent fbebe9f4f9
commit 4879fcfe90
20 changed files with 32 additions and 33 deletions

View File

@@ -6,19 +6,19 @@ class Pulse:
self.driver = driver
def run(self, preset):
self.driver.off()
# Get colors from preset
colors = preset.c
if not colors:
colors = [(255, 255, 255)]
bg_base = preset.background_or(colors)
self.driver.fill(self.driver.apply_brightness(bg_base, preset.b))
color_index = 0
color_index = self.driver.step % max(1, len(colors))
cycle_start = utime.ticks_ms()
# State machine based pulse using a single generator loop
while True:
bg_color = self.driver.apply_brightness(colors[-1], preset.b)
bg_color = self.driver.apply_brightness(bg_base, preset.b)
# Read current timing parameters from preset
attack_ms = max(0, int(preset.n1)) # Attack time in ms
hold_ms = max(0, int(preset.n2)) # Hold time in ms
@@ -53,7 +53,8 @@ class Pulse:
self.driver.fill(bg_color)
else:
# End of cycle, move to next color and restart timing
color_index += 1
color_index = (color_index + 1) % max(1, len(colors))
self.driver.step = color_index
cycle_start = now
if not preset.a:
break