Skip to content

Commit 35d8c01

Browse files
authored
Merge pull request #115 from tneish/horiz_animation
ColorCycle accepts start color
2 parents 0f24be5 + cba51fb commit 35d8c01

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

adafruit_led_animation/animation/colorcycle.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ class ColorCycle(Animation):
3838
:param float speed: Animation speed in seconds, e.g. ``0.1``.
3939
:param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex
4040
format. Defaults to a rainbow color cycle.
41+
:param start_color: An index (from 0) for which color to start from. Default 0 (first color).
4142
"""
4243

43-
def __init__(self, pixel_object, speed, colors=RAINBOW, name=None):
44+
# pylint: disable=too-many-arguments
45+
def __init__(self, pixel_object, speed, colors=RAINBOW, name=None, start_color=0):
4446
self.colors = colors
45-
super().__init__(pixel_object, speed, colors[0], name=name)
46-
self._generator = self._color_generator()
47+
self.start_color = start_color
48+
super().__init__(pixel_object, speed, colors[start_color], name=name)
49+
self._generator = self._color_generator(start_color)
4750
next(self._generator)
4851

4952
on_cycle_complete_supported = True
@@ -52,17 +55,17 @@ def draw(self):
5255
self.pixel_object.fill(self.color)
5356
next(self._generator)
5457

55-
def _color_generator(self):
56-
index = 0
58+
def _color_generator(self, start_color):
59+
index = start_color
5760
while True:
5861
self._color = self.colors[index]
5962
yield
6063
index = (index + 1) % len(self.colors)
61-
if index == 0:
64+
if index == start_color:
6265
self.cycle_complete = True
6366

6467
def reset(self):
6568
"""
6669
Resets to the first color.
6770
"""
68-
self._generator = self._color_generator()
71+
self._generator = self._color_generator(self.start_color)

0 commit comments

Comments
 (0)