Skip to content

Commit cce7094

Browse files
committed
ColorCycle accepts start color
1 parent 0f24be5 commit cce7094

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

adafruit_led_animation/animation/colorcycle.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ 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 given).
4142
"""
4243

43-
def __init__(self, pixel_object, speed, colors=RAINBOW, name=None):
44+
def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None):
4445
self.colors = colors
45-
super().__init__(pixel_object, speed, colors[0], name=name)
46-
self._generator = self._color_generator()
46+
super().__init__(pixel_object, speed, colors[start_color], name=name)
47+
self._generator = self._color_generator(start_color)
4748
next(self._generator)
4849

4950
on_cycle_complete_supported = True
@@ -52,8 +53,8 @@ def draw(self):
5253
self.pixel_object.fill(self.color)
5354
next(self._generator)
5455

55-
def _color_generator(self):
56-
index = 0
56+
def _color_generator(self, start_color):
57+
index = start_color
5758
while True:
5859
self._color = self.colors[index]
5960
yield

0 commit comments

Comments
 (0)