From: caternuson Date: Mon, 28 Feb 2022 18:38:35 +0000 (-0800) Subject: update colorwheel X-Git-Tag: 7.0.2^2 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/616000480943c728c2c15e17fb27ad3d0661779d update colorwheel --- diff --git a/src/rainbowio.py b/src/rainbowio.py index e852d83..a411e3d 100644 --- a/src/rainbowio.py +++ b/src/rainbowio.py @@ -4,7 +4,7 @@ See `CircuitPython:rainbowio` in CircuitPython for more details. Not supported by all boards. -* Author(s): Kattni Rembor +* Author(s): Kattni Rembor, Carter Nelson """ @@ -16,12 +16,23 @@ def colorwheel(color_value): :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: - 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 - 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