Merge pull request #54 from rhooper/blink-color-fix

Blink color fix
This commit is contained in:
Kattni 2020-06-22 19:15:41 -04:00 committed by GitHub
commit b5e75fa470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 16 deletions

View file

@ -68,7 +68,7 @@ class Animation:
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 @@ class Animation:
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 @@ class Animation:
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.

View file

@ -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]

View file

@ -92,10 +92,7 @@ class Comet(Animation):
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(

View file

@ -82,7 +82,7 @@ class RainbowComet(Comet):
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

View file

@ -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]

View file

@ -71,7 +71,7 @@ class Sparkle(Animation):
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)):

View file

@ -80,6 +80,9 @@ class SparklePulse(Sparkle):
)
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()