]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/rainbowio.py
ODROID-M1/S: Fix the i2c and serial pins
[Adafruit_Blinka-hackapet.git] / src / rainbowio.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 """
5 `rainbowio` - Provides the `colorwheel()` function
6 ===========================================================
7 See `CircuitPython:rainbowio` in CircuitPython for more details.
8 Not supported by all boards.
9
10 * Author(s): Kattni Rembor, Carter Nelson
11 """
12
13
14 def colorwheel(color_value):
15     """
16     A colorwheel. ``0`` and ``255`` are red, ``85`` is green, and ``170`` is blue, with the values
17     between being the rest of the rainbow.
18
19     :param int color_value: 0-255 of color value to return
20     :return: tuple of RGB values
21     """
22     color_value = int(color_value)
23     if color_value < 0 or color_value > 255:
24         r = 0
25         g = 0
26         b = 0
27     elif color_value < 85:
28         r = int(255 - color_value * 3)
29         g = int(color_value * 3)
30         b = 0
31     elif color_value < 170:
32         color_value -= 85
33         r = 0
34         g = int(255 - color_value * 3)
35         b = int(color_value * 3)
36     else:
37         color_value -= 170
38         r = int(color_value * 3)
39         g = 0
40         b = int(255 - color_value * 3)
41     return r << 16 | g << 8 | b