From cce709470f1ddbf07fd9ade2d27ab2892c2e12fb Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:15:27 +0100 Subject: [PATCH 1/4] ColorCycle accepts start color --- adafruit_led_animation/animation/colorcycle.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 5f27954..7251167 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -38,12 +38,13 @@ class ColorCycle(Animation): :param float speed: Animation speed in seconds, e.g. ``0.1``. :param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex format. Defaults to a rainbow color cycle. + :param start_color: An index (from 0) for which color to start from. Default 0 (first color given). """ - def __init__(self, pixel_object, speed, colors=RAINBOW, name=None): + def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): self.colors = colors - super().__init__(pixel_object, speed, colors[0], name=name) - self._generator = self._color_generator() + super().__init__(pixel_object, speed, colors[start_color], name=name) + self._generator = self._color_generator(start_color) next(self._generator) on_cycle_complete_supported = True @@ -52,8 +53,8 @@ def draw(self): self.pixel_object.fill(self.color) next(self._generator) - def _color_generator(self): - index = 0 + def _color_generator(self, start_color): + index = start_color while True: self._color = self.colors[index] yield From da467ce9b7eeddfe64ee0a6783b02430729235f7 Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:23:17 +0100 Subject: [PATCH 2/4] Fix pylint errors --- adafruit_led_animation/animation/colorcycle.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 7251167..c945351 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -38,11 +38,13 @@ class ColorCycle(Animation): :param float speed: Animation speed in seconds, e.g. ``0.1``. :param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex format. Defaults to a rainbow color cycle. - :param start_color: An index (from 0) for which color to start from. Default 0 (first color given). + :param start_color: An index (from 0) for which color to start from. Default 0 (first color). """ - + + # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): self.colors = colors + self.start_color = start_color super().__init__(pixel_object, speed, colors[start_color], name=name) self._generator = self._color_generator(start_color) next(self._generator) @@ -66,4 +68,4 @@ def reset(self): """ Resets to the first color. """ - self._generator = self._color_generator() + self._generator = self._color_generator(self.start_color) From 43aa654b4d7c115ec523f802633230feff9f58e4 Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Wed, 27 Dec 2023 22:33:33 +0100 Subject: [PATCH 3/4] cycle complete at start_color --- adafruit_led_animation/animation/colorcycle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index c945351..5f3b244 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -40,7 +40,7 @@ class ColorCycle(Animation): format. Defaults to a rainbow color cycle. :param start_color: An index (from 0) for which color to start from. Default 0 (first color). """ - + # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): self.colors = colors @@ -61,7 +61,7 @@ def _color_generator(self, start_color): self._color = self.colors[index] yield index = (index + 1) % len(self.colors) - if index == 0: + if index == start_color: self.cycle_complete = True def reset(self): From cba51fb34b2c1b49ffc5d9ae694ba29d8f6a7be3 Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Wed, 27 Dec 2023 22:40:48 +0100 Subject: [PATCH 4/4] Update adafruit_led_animation/animation/colorcycle.py Adding the new arg to the end will make any calls upward.compatible Co-authored-by: Dan Halbert --- adafruit_led_animation/animation/colorcycle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 5f3b244..41bff44 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -42,7 +42,7 @@ class ColorCycle(Animation): """ # pylint: disable=too-many-arguments - def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): + def __init__(self, pixel_object, speed, colors=RAINBOW, name=None, start_color=0): self.colors = colors self.start_color = start_color super().__init__(pixel_object, speed, colors[start_color], name=name)