diff --git a/adafruit_led_animation/animation/__init__.py b/adafruit_led_animation/animation/__init__.py index 5265296..2876afe 100644 --- a/adafruit_led_animation/animation/__init__.py +++ b/adafruit_led_animation/animation/__init__.py @@ -68,7 +68,7 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No self._time_left_at_pause = 0 self._also_notify = [] self.speed = speed # sets _speed_ns - self.color = color # Triggers _recompute_color + self.color = color # Triggers _set_color self.name = name self.cycle_complete = False self.notify_cycles = 1 @@ -187,8 +187,14 @@ def color(self, color): return if isinstance(color, int): color = (color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF) + self._set_color(color) + + def _set_color(self, color): + """ + Called after the color is changed, which includes at initialization. + Override as needed. + """ self._color = color - self._recompute_color(color) @property def speed(self): @@ -201,12 +207,6 @@ def speed(self): def speed(self, seconds): self._speed_ns = int(seconds * NANOS_PER_SECOND) - def _recompute_color(self, color): - """ - Called if the color is changed, which includes at initialization. - Override as needed. - """ - def on_cycle_complete(self): """ Called by some animations when they complete an animation cycle. diff --git a/adafruit_led_animation/animation/blink.py b/adafruit_led_animation/animation/blink.py index fe6ec10..8d482f8 100644 --- a/adafruit_led_animation/animation/blink.py +++ b/adafruit_led_animation/animation/blink.py @@ -60,5 +60,5 @@ class Blink(ColorCycle): def __init__(self, pixel_object, speed, color, name=None): super().__init__(pixel_object, speed, [color, BLACK], name=name) - def _recompute_color(self, color): + def _set_color(self, color): self.colors = [color, BLACK] diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index bbe54e7..85e36d2 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -92,10 +92,7 @@ def __init__( on_cycle_complete_supported = True - def _recompute_color(self, color): - self._comet_recompute_color(color) - - def _comet_recompute_color(self, color): + def _set_color(self, color): self._comet_colors = [BLACK] for n in range(self._tail_length): self._comet_colors.append( diff --git a/adafruit_led_animation/animation/rainbowcomet.py b/adafruit_led_animation/animation/rainbowcomet.py index 572f859..3cc84bf 100644 --- a/adafruit_led_animation/animation/rainbowcomet.py +++ b/adafruit_led_animation/animation/rainbowcomet.py @@ -82,7 +82,7 @@ def __init__( self._colorwheel_offset = colorwheel_offset super().__init__(pixel_object, speed, 0, tail_length, reverse, bounce, name) - def _comet_recompute_color(self, color): + def _set_color(self, color): self._comet_colors = [BLACK] for n in range(self._tail_length): invert = self._tail_length - n - 1 diff --git a/adafruit_led_animation/animation/solid.py b/adafruit_led_animation/animation/solid.py index 7fa90e6..497fff3 100644 --- a/adafruit_led_animation/animation/solid.py +++ b/adafruit_led_animation/animation/solid.py @@ -58,5 +58,5 @@ class Solid(ColorCycle): def __init__(self, pixel_object, color, name=None): super().__init__(pixel_object, speed=1, colors=[color], name=name) - def _recompute_color(self, color): + def _set_color(self, color): self.colors = [color] diff --git a/adafruit_led_animation/animation/sparkle.py b/adafruit_led_animation/animation/sparkle.py index 8f0e691..b975f24 100644 --- a/adafruit_led_animation/animation/sparkle.py +++ b/adafruit_led_animation/animation/sparkle.py @@ -71,7 +71,7 @@ def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None): self._pixels = [] super().__init__(pixel_object, speed, color, name=name) - def _recompute_color(self, color): + def _set_color(self, color): half_color = tuple(color[rgb] // 4 for rgb in range(len(color))) dim_color = tuple(color[rgb] // 10 for rgb in range(len(color))) for pixel in range(len(self.pixel_object)): diff --git a/adafruit_led_animation/animation/sparklepulse.py b/adafruit_led_animation/animation/sparklepulse.py index 8e41bf2..9a06848 100644 --- a/adafruit_led_animation/animation/sparklepulse.py +++ b/adafruit_led_animation/animation/sparklepulse.py @@ -80,6 +80,9 @@ def __init__( ) self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar) + def _set_color(self, color): + self._color = color + def draw(self): self._sparkle_color = next(self._generator) super().draw()