Skip to content

Commit 48ff1e8

Browse files
authored
Merge pull request #49 from nnja/fix_sparkle_and_sparklepulse_animations
Fix off by 1 error affecting Sparkle and SparkePulse animations
2 parents 67ccb54 + da0d851 commit 48ff1e8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

adafruit_led_animation/animation/sparkle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None):
6868
self._dim_color = color
6969
self._sparkle_color = color
7070
self._num_sparkles = num_sparkles
71+
self._num_pixels = len(pixel_object)
7172
self._pixels = []
7273
super().__init__(pixel_object, speed, color, name=name)
7374

@@ -85,7 +86,7 @@ def _set_color(self, color):
8586

8687
def draw(self):
8788
self._pixels = [
88-
random.randint(0, (len(self.pixel_object) - 2))
89+
random.randint(0, (len(self.pixel_object) - 1))
8990
for _ in range(self._num_sparkles)
9091
]
9192
for pixel in self._pixels:
@@ -94,5 +95,5 @@ def draw(self):
9495
def after_draw(self):
9596
self.show()
9697
for pixel in self._pixels:
97-
self.pixel_object[pixel] = self._half_color
98-
self.pixel_object[pixel + 1] = self._dim_color
98+
self.pixel_object[pixel % self._num_pixels] = self._half_color
99+
self.pixel_object[(pixel + 1) % self._num_pixels] = self._dim_color

0 commit comments

Comments
 (0)