|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (c) 2019-2020 Roy Hooper |
| 4 | +# Copyright (c) 2020 Kattni Rembor for Adafruit Industries |
| 5 | +# Copyright (c) 2020 Connie Sieh |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in |
| 15 | +# all copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +# THE SOFTWARE. |
| 24 | +""" |
| 25 | +`adafruit_led_animation.animation.customcolorchase` |
| 26 | +================================================================================ |
| 27 | +
|
| 28 | +Custom color chase animation for CircuitPython helper library for LED animations. |
| 29 | +
|
| 30 | +* Author(s): Roy Hooper, Kattni Rembor, Connie Sieh |
| 31 | +
|
| 32 | +Implementation Notes |
| 33 | +-------------------- |
| 34 | +
|
| 35 | +**Hardware:** |
| 36 | +
|
| 37 | +* `Adafruit NeoPixels <https://www.adafruit.com/category/168>`_ |
| 38 | +* `Adafruit DotStars <https://www.adafruit.com/category/885>`_ |
| 39 | +
|
| 40 | +**Software and Dependencies:** |
| 41 | +
|
| 42 | +* Adafruit CircuitPython firmware for the supported boards: |
| 43 | + https://circuitpython.org/downloads |
| 44 | +
|
| 45 | +
|
| 46 | +""" |
| 47 | + |
| 48 | +from adafruit_led_animation.animation.chase import Chase |
| 49 | +from adafruit_led_animation.color import RAINBOW |
| 50 | + |
| 51 | + |
| 52 | +class CustomColorChase(Chase): |
| 53 | + """ |
| 54 | + Chase pixels in one direction, like a theater marquee with Custom Colors |
| 55 | +
|
| 56 | + :param pixel_object: The initialised LED object. |
| 57 | + :param float speed: Animation speed rate in seconds, e.g. ``0.1``. |
| 58 | + :param colors: Animation colors in list of `(r, g, b)`` tuple, or ``0x000000`` hex format |
| 59 | + :param size: Number of pixels to turn on in a row. |
| 60 | + :param spacing: Number of pixels to turn off in a row. |
| 61 | + :param reverse: Reverse direction of movement. |
| 62 | + """ |
| 63 | + |
| 64 | + # pylint: disable=too-many-arguments |
| 65 | + def __init__( |
| 66 | + self, |
| 67 | + pixel_object, |
| 68 | + speed, |
| 69 | + size=2, |
| 70 | + spacing=3, |
| 71 | + reverse=False, |
| 72 | + name=None, |
| 73 | + colors=RAINBOW, |
| 74 | + ): |
| 75 | + self._num_colors = len(colors) |
| 76 | + self._colors = colors |
| 77 | + self._color_idx = 0 |
| 78 | + super().__init__(pixel_object, speed, 0, size, spacing, reverse, name) |
| 79 | + |
| 80 | + def bar_color(self, n, pixel_no=0): |
| 81 | + return self._colors[self._color_idx - (n % len(self._colors))] |
| 82 | + |
| 83 | + def on_cycle_complete(self): |
| 84 | + self._color_idx = (self._color_idx + self._direction) % len(self._colors) |
| 85 | + super().on_cycle_complete() |
0 commit comments