X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/a79eb436569f2c4d1390571eba5779fc5aedf6db..6b55de23ca16ffb92eddb5511dee72829d2dbd85:/src/rainbowio.py 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