]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/rainbowio.py
Revert "don't upload universal bdist to pypi"
[Adafruit_Blinka-hackapet.git] / src / rainbowio.py
index b7bc06a8110b558e29d4c534ed1322d1c9fbd693..5ed5a3a29df849654c9c092b266e5657713c9a3e 100644 (file)
@@ -1,17 +1,16 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """
 `rainbowio` - Provides the `colorwheel()` function
 ===========================================================
 See `CircuitPython:rainbowio` in CircuitPython for more details.
 Not supported by all boards.
 
 """
 `rainbowio` - Provides the `colorwheel()` function
 ===========================================================
 See `CircuitPython:rainbowio` in CircuitPython for more details.
 Not supported by all boards.
 
-* Author(s): Kattni Rembor
+* Author(s): Kattni Rembor, Carter Nelson
 """
 
 
 """
 
 
-__version__ = "0.0.0-auto.0"
-__repo__ = "https://github.com/adafruit/Adafruit_Blinka.git"
-
-
 def colorwheel(color_value):
     """
     A colorwheel. ``0`` and ``255`` are red, ``85`` is green, and ``170`` is blue, with the values
 def colorwheel(color_value):
     """
     A colorwheel. ``0`` and ``255`` are red, ``85`` is green, and ``170`` is blue, with the values
@@ -20,12 +19,23 @@ def colorwheel(color_value):
     :param int color_value: 0-255 of color value to return
     :return: tuple of RGB values
     """
     :param int color_value: 0-255 of color value to return
     :return: tuple of RGB values
     """
+    color_value = int(color_value)
     if color_value < 0 or color_value > 255:
     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:
+        r = 0
+        g = 0
+        b = 0
+    elif color_value < 85:
+        r = int(255 - color_value * 3)
+        g = int(color_value * 3)
+        b = 0
+    elif color_value < 170:
         color_value -= 85
         color_value -= 85
-        return 0, 255 - color_value * 3, color_value * 3
-    color_value -= 170
-    return color_value * 3, 0, 255 - color_value * 3
+        r = 0
+        g = int(255 - color_value * 3)
+        b = int(color_value * 3)
+    else:
+        color_value -= 170
+        r = int(color_value * 3)
+        g = 0
+        b = int(255 - color_value * 3)
+    return r << 16 | g << 8 | b