Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating brightness mid-animation #65

Open
stickperson opened this issue Sep 11, 2020 · 1 comment
Open

Updating brightness mid-animation #65

stickperson opened this issue Sep 11, 2020 · 1 comment

Comments

@stickperson
Copy link

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.

@steveof2620
Copy link

Would also like a way to adjust the speed within the while True loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants