8000 Optimizations by jepler · Pull Request #103 · adafruit/Adafruit_CircuitPython_LED_Animation · GitHub
[go: up one dir, main page]

Skip to content

Optimizations #103

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 2 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion adafruit_led_animation/animation/chase.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def bar_colors():
bar_no += 1

colorgen = bar_colors()
self.pixel_object[:] = [next(colorgen) for _ in self.pixel_object]
self.pixel_object[:] = [next(colorgen) for _ in range(len(self.pixel_object))]

if self.draw_count % len(self.pixel_object) == 0:
self.cycle_complete = True
Expand Down
26 changes: 18 additions & 8 deletions adafruit_led_animation/animation/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,24 @@ def draw(self):
colors = self._comet_colors
if self.reverse:
colors = reversed(colors)
for pixel_no, color in enumerate(colors):
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

pixels = self.pixel_object
start = self._tail_start
npixels = len(pixels)
if self._ring:
start %= npixels
for color in colors:
pixels[start] = color
start += 1
if start == npixels:
start = 0
else:
for color in colors:
if start >= npixels:
break
if start >= 0:
pixels[start] = color
start += 1

self._tail_start += self._direction

Expand Down
0