Skip to content

Commit 7b5ba82

Browse files
committed
fix color setting so that animations like blink aren't reset on color setting
1 parent 3dbe521 commit 7b5ba82

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

adafruit_led_animation/animation/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No
6868
self._time_left_at_pause = 0
6969
self._also_notify = []
7070
self.speed = speed # sets _speed_ns
71-
self.color = color # Triggers _recompute_color
71+
self.color = color # Triggers _set_color
7272
self.name = name
7373
self.cycle_complete = False
7474
self.notify_cycles = 1
@@ -185,10 +185,16 @@ def color(self):
185185
def color(self, color):
186186
if self._color == color:
187187
return
188+
self._set_color(color)
189+
190+
def _set_color(self, color):
191+
"""
192+
Called after the color is changed, which includes at initialization.
193+
Override as needed.
194+
"""
188195
if isinstance(color, int):
189196
color = (color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF)
190197
self._color = color
191-
self._recompute_color(color)
192198

193199
@property
194200
def speed(self):
@@ -201,12 +207,6 @@ def speed(self):
201207
def speed(self, seconds):
202208
self._speed_ns = int(seconds * NANOS_PER_SECOND)
203209

204-
def _recompute_color(self, color):
205-
"""
206-
Called if the color is changed, which includes at initialization.
207-
Override as needed.
208-
"""
209-
210210
def on_cycle_complete(self):
211211
"""
212212
Called by some animations when they complete an animation cycle.

adafruit_led_animation/animation/blink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ class Blink(ColorCycle):
6060
def __init__(self, pixel_object, speed, color, name=None):
6161
super().__init__(pixel_object, speed, [color, BLACK], name=name)
6262

63-
def _recompute_color(self, color):
63+
def _set_color(self, color):
6464
self.colors = [color, BLACK]

adafruit_led_animation/animation/comet.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ def __init__(
9292

9393
on_cycle_complete_supported = True
9494

95-
def _recompute_color(self, color):
96-
self._comet_recompute_color(color)
97-
98-
def _comet_recompute_color(self, color):
95+
def _set_color(self, color):
9996
self._comet_colors = [BLACK]
10097
for n in range(self._tail_length):
10198
self._comet_colors.append(

adafruit_led_animation/animation/rainbowcomet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
self._colorwheel_offset = colorwheel_offset
8383
super().__init__(pixel_object, speed, 0, tail_length, reverse, bounce, name)
8484

85-
def _comet_recompute_color(self, color):
85+
def _set_color(self, color):
8686
self._comet_colors = [BLACK]
8787
for n in range(self._tail_length):
8888
invert = self._tail_length - n - 1

adafruit_led_animation/animation/solid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ class Solid(ColorCycle):
5858
def __init__(self, pixel_object, color, name=None):
5959
super().__init__(pixel_object, speed=1, colors=[color], name=name)
6060

61-
def _recompute_color(self, color):
61+
def _set_color(self, color):
6262
self.colors = [color]

adafruit_led_animation/animation/sparkle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None):
7171
self._pixels = []
7272
super().__init__(pixel_object, speed, color, name=name)
7373

74-
def _recompute_color(self, color):
74+
def _set_color(self, color):
7575
half_color = tuple(color[rgb] // 4 for rgb in range(len(color)))
7676
dim_color = tuple(color[rgb] // 10 for rgb in range(len(color)))
7777
for pixel in range(len(self.pixel_object)):

0 commit comments

Comments
 (0)