1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
5 `rainbowio` - Provides the `colorwheel()` function
6 ===========================================================
7 See `CircuitPython:rainbowio` in CircuitPython for more details.
8 Not supported by all boards.
10 * Author(s): Kattni Rembor, Carter Nelson
14 def colorwheel(color_value):
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.
19 :param int color_value: 0-255 of color value to return
20 :return: tuple of RGB values
22 color_value = int(color_value)
23 if color_value < 0 or color_value > 255:
27 elif color_value < 85:
28 r = int(255 - color_value * 3)
29 g = int(color_value * 3)
31 elif color_value < 170:
34 g = int(255 - color_value * 3)
35 b = int(color_value * 3)
38 r = int(color_value * 3)
40 b = int(255 - color_value * 3)
41 return r << 16 | g << 8 | b