From: Kattni Rembor Date: Tue, 13 Jul 2021 18:56:02 +0000 (-0400) Subject: Add rainbowio to Blinka. X-Git-Tag: 6.11.0^2~2 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/6b55de23ca16ffb92eddb5511dee72829d2dbd85?ds=inline Add rainbowio to Blinka. --- diff --git a/setup.py b/setup.py index 5d6ea95..576afbd 100755 --- a/setup.py +++ b/setup.py @@ -57,6 +57,7 @@ setup( "pulseio", "pwmio", "neopixel_write", + "rainbowio", ], package_data={ "adafruit_blinka.microcontroller.bcm283x.pulseio": ["libgpiod_pulsein"] diff --git a/src/rainbowio.py b/src/rainbowio.py new file mode 100644 index 0000000..e852d83 --- /dev/null +++ b/src/rainbowio.py @@ -0,0 +1,27 @@ +""" +`rainbowio` - Provides the `colorwheel()` function +=========================================================== +See `CircuitPython:rainbowio` in CircuitPython for more details. +Not supported by all boards. + +* Author(s): Kattni Rembor +""" + + +def colorwheel(color_value): + """ + A colorwheel. ``0`` and ``255`` are red, ``85`` is green, and ``170`` is blue, with the values + between being the rest of the rainbow. + + :param int color_value: 0-255 of color value to return + :return: tuple of RGB values + """ + if color_value < 0 or color_value > 255: + return 0, 0, 0 + if color_value < 85: + return 255 - color_value * 3, color_value * 3, 0 + if color_value < 170: + color_value -= 85 + return 0, 255 - color_value * 3, color_value * 3 + color_value -= 170 + return color_value * 3, 0, 255 - color_value * 3