Skip to content

Fix off by 1 error affecting Sparkle and SparkePulse animations #49

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions adafruit_led_animation/animation/sparkle.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None):
self._dim_color = color
self._sparkle_color = color
self._num_sparkles = num_sparkles
self._num_pixels = len(pixel_object)
self._pixels = []
super().__init__(pixel_object, speed, color, name=name)

Expand All @@ -85,7 +86,7 @@ def _recompute_color(self, color):

def draw(self):
self._pixels = [
random.randint(0, (len(self.pixel_object) - 2))
random.randint(0, (len(self.pixel_object) - 1))
for _ in range(self._num_sparkles)
]
for pixel in self._pixels:
Expand All @@ -94,5 +95,5 @@ def draw(self):
def after_draw(self):
self.show()
for pixel in self._pixels:
self.pixel_object[pixel] = self._half_color
self.pixel_object[pixel + 1] = self._dim_color
self.pixel_object[pixel % self._num_pixels] = self._half_color
self.pixel_object[(pixel + 1) % self._num_pixels] = self._dim_color