@@ -38,12 +38,15 @@ class ColorCycle(Animation):
38
38
:param float speed: Animation speed in seconds, e.g. ``0.1``.
39
39
:param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex
40
40
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).
41
42
"""
42
43
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 ):
44
46
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 )
47
50
next (self ._generator )
48
51
49
52
on_cycle_complete_supported = True
@@ -52,17 +55,17 @@ def draw(self):
52
55
self .pixel_object .fill (self .color )
53
56
next (self ._generator )
54
57
55
- def _color_generator (self ):
56
- index = 0
58
+ def _color_generator (self , start_color ):
59
+ index = start_color
57
60
while True :
58
61
self ._color = self .colors [index ]
59
62
yield
60
63
index = (index + 1 ) % len (self .colors )
61
- if index == 0 :
64
+ if index == start_color :
62
65
self .cycle_complete = True
63
66
64
67
def reset (self ):
65
68
"""
66
69
Resets to the first color.
67
70
"""
68
- self ._generator = self ._color_generator ()
71
+ self ._generator = self ._color_generator (self . start_color )
0 commit comments