feat(patterns): reverse animation direction via preset n8

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-17 18:32:01 +12:00
parent 55a97ac51c
commit 94266d5a7c
11 changed files with 131 additions and 62 deletions

View File

@@ -30,9 +30,9 @@ class Meteor:
base = colors[color_index % len(colors)]
lit = self.driver.apply_brightness(base, preset.b)
if 0 <= head < self.driver.num_leds:
self.driver.n[head] = lit
self.driver.n[self.driver.led_i(preset, head)] = lit
self.driver.n.write()
head += direction * speed
head += self.driver.signed(preset, direction * speed)
if head >= self.driver.num_leds + tail_len:
head = self.driver.num_leds - 1
direction = -1
@@ -62,14 +62,22 @@ class Meteor:
i1 = p1 - t
if 0 <= i1 < self.driver.num_leds:
s = (255 * (tail - t)) // max(1, tail)
self.driver.n[i1] = ((c1[0] * s) // 255, (c1[1] * s) // 255, (c1[2] * s) // 255)
self.driver.n[self.driver.led_i(preset, i1)] = (
(c1[0] * s) // 255,
(c1[1] * s) // 255,
(c1[2] * s) // 255,
)
i2 = p2 + t
if 0 <= i2 < self.driver.num_leds:
s = (255 * (tail - t)) // max(1, tail)
self.driver.n[i2] = ((c2[0] * s) // 255, (c2[1] * s) // 255, (c2[2] * s) // 255)
self.driver.n[self.driver.led_i(preset, i2)] = (
(c2[0] * s) // 255,
(c2[1] * s) // 255,
(c2[2] * s) // 255,
)
self.driver.n.write()
p1 += speed
p2 -= speed
p1 += self.driver.signed(preset, speed)
p2 -= self.driver.signed(preset, speed)
if p1 - tail > self.driver.num_leds and p2 + tail < 0:
p1 = 0
p2 = self.driver.num_leds - 1 - gap
@@ -89,10 +97,10 @@ class Meteor:
if dist < 0:
dist = -dist
if dist > width:
self.driver.n[i] = bg_color
self.driver.n[self.driver.led_i(preset, i)] = bg_color
else:
scale = ((width - dist) * 255) // max(1, width)
self.driver.n[i] = (
self.driver.n[self.driver.led_i(preset, i)] = (
(base[0] * scale) // 255,
(base[1] * scale) // 255,
(base[2] * scale) // 255,
@@ -101,7 +109,7 @@ class Meteor:
if pause_frames > 0:
pause_frames -= 1
else:
center += direction
center += self.driver.signed(preset, direction)
if center >= self.driver.num_leds - 1:
center = self.driver.num_leds - 1
direction = -1
@@ -121,7 +129,11 @@ class Meteor:
if mode == 1:
gap = max(0, int(preset.n3))
p1, p2 = 0, self.driver.num_leds - 1 - gap
nled = self.driver.num_leds
if self.driver.is_reversed(preset):
p1, p2 = nled - 1, gap
else:
p1, p2 = 0, nled - 1 - gap
last = utime.ticks_ms()
while True:
p1, p2, last, stepped = self._run_comet_dual(preset, colors, p1, p2, last)
@@ -131,7 +143,11 @@ class Meteor:
yield
if mode == 2:
color_index, center, direction, pause_frames = 0, 0, 1, 0
nled = self.driver.num_leds
if self.driver.is_reversed(preset):
color_index, center, direction, pause_frames = 0, max(0, nled - 1), -1, 0
else:
color_index, center, direction, pause_frames = 0, 0, 1, 0
last_update = utime.ticks_ms()
while True:
color_index, center, direction, pause_frames, last_update, stepped = (
@@ -144,7 +160,11 @@ class Meteor:
return
yield
color_index, head, direction = 0, 0, 1
nled = self.driver.num_leds
if self.driver.is_reversed(preset):
color_index, head, direction = 0, max(0, nled - 1), -1
else:
color_index, head, direction = 0, 0, 1
last_update = utime.ticks_ms()
while True:
color_index, head, direction, last_update, stepped = self._run_meteor(