From da0d851323ff62c1c691b48b61344fe50d35db1a Mon Sep 17 00:00:00 2001 From: Nina Zakharenko Date: Sat, 13 Jun 2020 22:37:22 -0700 Subject: [PATCH] Fix off by 1 error affecting sparkles --- adafruit_led_animation/animation/sparkle.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_led_animation/animation/sparkle.py b/adafruit_led_animation/animation/sparkle.py index 8f0e691..78962b7 100644 --- a/adafruit_led_animation/animation/sparkle.py +++ b/adafruit_led_animation/animation/sparkle.py @@ -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) @@ -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: @@ -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