Updating brightness mid-animation
stickperson opened this issue · 2 comments
Any idea how difficult it would be to make it easier to update the brightness of the animation once it has been created? I'm using a RainbowComet
animation with a PixelSubset
. While that's running I also have a customized Pulse
animation running on another subset of pixels. As pulse.draw()
is called I keep track of the current brightness level so that my other LEDs can change as well.
I'd like the brightness of the RainbowComet
animation to be in sync with that of my customized Pulse
animation. To do that, I created a slightly customized RainbowComet
class that overrides the draw
method to use the current brightness:
def draw(self):
"""
Same exact implementation as the base class except adding in current brightness
"""
# super().draw()
colors = self._comet_colors
if self.reverse:
colors = reversed(colors)
for pixel_no, color in enumerate(colors):
# The next three lines were added to add in brightness
if len(color) == 3:
color = list(color)
color.append(self.displayer.current_brightness / 100)
draw_at = self._tail_start + pixel_no
if draw_at < 0 or draw_at >= self._num_pixels:
if not self._ring:
continue
draw_at = draw_at % self._num_pixels
self.pixel_object[draw_at] = color
self._tail_start += self._direction
if self._tail_start < self._left_side or self._tail_start >= self._right_side:
if self.bounce:
self.reverse = not self.reverse
self._direction = -self._direction
elif self._ring:
self._tail_start = self._tail_start % self._num_pixels
else:
self.reset()
if self.reverse == self._initial_reverse and self.draw_count > 0:
self.cycle_complete = True
I tried animation._pixel_object.brightness
but that ended poorly.
Would also like a way to adjust the speed within the while True loop.