]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/rainbowio.py
Add the examples that exist to the documention.
[Adafruit_Blinka-hackapet.git] / src / rainbowio.py
1 """
2 `rainbowio` - Provides the `colorwheel()` function
3 ===========================================================
4 See `CircuitPython:rainbowio` in CircuitPython for more details.
5 Not supported by all boards.
6
7 * Author(s): Kattni Rembor
8 """
9
10
11 __version__ = "0.0.0-auto.0"
12 __repo__ = "https://github.com/adafruit/Adafruit_Blinka.git"
13
14
15 def colorwheel(color_value):
16     """
17     A colorwheel. ``0`` and ``255`` are red, ``85`` is green, and ``170`` is blue, with the values
18     between being the rest of the rainbow.
19
20     :param int color_value: 0-255 of color value to return
21     :return: tuple of RGB values
22     """
23     if color_value < 0 or color_value > 255:
24         return 0, 0, 0
25     if color_value < 85:
26         return 255 - color_value * 3, color_value * 3, 0
27     if color_value < 170:
28         color_value -= 85
29         return 0, 255 - color_value * 3, color_value * 3
30     color_value -= 170
31     return color_value * 3, 0, 255 - color_value * 3