Skip to content

Commit fc752db

Browse files
committed
fix comet going too far off left and right edges
1 parent 1a59bc8 commit fc752db

File tree

1 file changed

+5
-6
lines changed
  • adafruit_led_animation/animation

1 file changed

+5
-6
lines changed

adafruit_led_animation/animation/comet.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def __init__(
8484
self._computed_color = color
8585
self._num_pixels = len(pixel_object)
8686
self._direction = -1 if reverse else 1
87-
self._left_side = -self._tail_length - 1
88-
self._right_side = self._num_pixels + self._tail_length + 1
87+
self._left_side = -self._tail_length
88+
self._right_side = self._num_pixels
8989
self._tail_start = 0
9090
self.reset()
9191
super().__init__(pixel_object, speed, color, name=name)
@@ -105,17 +105,16 @@ def _comet_recompute_color(self, color):
105105

106106
def draw(self):
107107
for pixel_no in range(self._tail_length + 1):
108-
draw_at = self._tail_start + (self._direction * pixel_no)
108+
draw_at = self._tail_start + pixel_no
109109
if draw_at < 0 or draw_at >= self._num_pixels:
110110
continue
111-
self.pixel_object[draw_at] = self._comet_colors[pixel_no]
111+
self.pixel_object[draw_at] = self._comet_colors[pixel_no * self._direction]
112112

113113
self._tail_start += self._direction
114114

115-
if self._tail_start < self._left_side or self._tail_start > self._right_side:
115+
if self._tail_start < self._left_side or self._tail_start >= self._right_side:
116116
self.reverse = not self.reverse
117117
self._direction = -self._direction
118-
self._tail_start += self._direction
119118
if self.reverse == self._initial_reverse:
120119
self.cycle_complete = True
121120

0 commit comments

Comments
 (0)