0

color.py update
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

color.py update

by blakebr on Tue Sep 14, 2021 2:37 pm

Hello Kattni,

The color.py file in adafruit_led_animation is missing some colors. Attached is a possible replacement.
All your original colors are preserved.
Matching color names start with NEW_ for those with different tupples.
Matching color names where the tupples are the same are commented out (#) in the added colors.
There are over 145 colors in the replacement file.
I have included your comments and code outside of the colors. I am running it.
I claim no license for my addition to your code.

Why is C o n f l i c t i n g a banned word?

Bruce

Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_led_animation.color`
================================================================================

Color variables assigned to RGB values made available for import.

* Author(s): Kattni Rembor

Implementation Notes
--------------------

**Hardware:**

* `Adafruit NeoPixels <https://www.adafruit.com/category/168>`_
* `Adafruit DotStars <https://www.adafruit.com/category/885>`_

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
  https://circuitpython.org/downloads
"""

MAROON = (128,0,0)
DARK_RED = (139,0,0)
BROWN = (165,42,42)
FIREBRICK = (178,34,34)
CRIMSON = (220,20,60)
#RED = (255,0,0)
TOMATO = (255,99,71)
CORAL = (255,127,80)
LIGHT_CORAL = (240,128,128)
DARK_SALMON = (233,150,122)
SALMON = (250,128,114)
LIGHT_SALMON = (255,160,122)
ORANGE_RED = (255,69,0)
DARK_ORANGE = (255,140,0)
NEW_ORANGE = (255,165,0)
NEW_GOLD = (255,215,0)
DARK_GOLDEN_ROD = (184,134,11)
GOLDEN_ROD = (218,165,32)
PALE_GOLDEN_ROD = (238,232,170)
DARK_KHAKI = (189,183,107)
KHAKI = (240,230,140)
OLIVE = (128,128,0)
NEW_YELLOW = (255,255,0)
YELLOW_GREEN = (154,205,50)
DARK_OLIVE_GREEN = (85,107,47)
OLIVE_DRAB = (107,142,35)
LAWN_GREEN = (124,252,0)
CHART_REUSE = (127,255,0)
GREEN_YELLOW = (173,255,47)
DARK_GREEN = (0,100,0)
GREEN = (0,128,0)
FOREST_GREEN = (34,139,34)
LIME = (0,255,0)
LIME_GREEN = (50,205,50)
LIGHT_GREEN = (144,238,144)
PALE_GREEN = (152,251,152)
DARK_SEA_GREEN = (143,188,143)
MEDIUM_SPRING_GREEN = (0,250,154)
SPRING_GREEN = (0,255,127)
SEA_GREEN = (46,139,87)
MEDIUM_AQUA_MARINE = (102,205,170)
MEDIUM_SEA_GREEN = (60,179,113)
LIGHT_SEA_GREEN = (32,178,170)
DARK_SLATE_GRAY = (47,79,79)
NEW_TEAL = (0,128,128)
DARK_CYAN = (0,139,139)
NEW_AQUA = (0,255,255)
#CYAN = (0,255,255)
LIGHT_CYAN = (224,255,255)
DARK_TURQUOISE = (0,206,209)
TURQUOISE = (64,224,208)
MEDIUM_TURQUOISE = (72,209,204)
PALE_TURQUOISE = (175,238,238)
AQUA_MARINE = (127,255,212)
POWDER_BLUE = (176,224,230)
CADET_BLUE = (95,158,160)
STEEL_BLUE = (70,130,180)
CORN_FLOWER_BLUE = (100,149,237)
DEEP_SKY_BLUE = (0,191,255)
DODGER_BLUE = (30,144,255)
LIGHT_BLUE = (173,216,230)
SKY_BLUE = (135,206,235)
LIGHT_SKY_BLUE = (135,206,250)
MIDNIGHT_BLUE = (25,25,112)
NAVY = (0,0,128)
DARK_BLUE = (0,0,139)
MEDIUM_BLUE = (0,0,205)
#BLUE = (0,0,255)
ROYAL_BLUE = (65,105,225)
BLUE_VIOLET = (138,43,226)
INDIGO = (75,0,130)
DARK_SLATE_BLUE = (72,61,139)
SLATE_BLUE = (106,90,205)
MEDIUM_SLATE_BLUE = (123,104,238)
MEDIUM_PURPLE = (147,112,219)
DARK_MAGENTA = (139,0,139)
DARK_VIOLET = (148,0,211)
DARK_ORCHID = (153,50,204)
MEDIUM_ORCHID = (186,85,211)
NEW_PURPLE = (128,0,128)
THISTLE = (216,191,216)
PLUM = (221,160,221)
VIOLET = (238,130,238)
FUCHSIA = (255,0,255)
NEW_MAGENTA = (255,0,255)
ORCHID = (218,112,214)
MEDIUM_VIOLET_RED = (199,21,133)
PALE_VIOLET_RED = (219,112,147)
DEEP_PINK = (255,20,147)
HOT_PINK = (255,105,180)
LIGHT_PINK = (255,182,193)
NEW_PINK = (255,192,203)
ANTIQUE_WHITE = (250,235,215)
BEIGE = (245,245,220)
BISQUE = (255,228,196)
WHEAT = (245,222,179)
CORN_SILK = (255,248,220)
LEMON_CHIFFON = (255,250,205)
LIGHT_GOLDEN_ROD_YELLOW = (250,250,210)
LIGHT_YELLOW = (255,255,224)
SADDLE_BROWN = (139,69,19)
SIENNA = (160,82,45)
CHOCOLATE = (210,105,30)
PERU = (205,133,63)
SANDY_BROWN = (244,164,96)
BURLY_WOOD = (222,184,135)
TAN = (210,180,140)
ROSY_BROWN = (188,143,143)
MOCCASIN = (255,228,181)
NAVAJO_WHITE = (255,222,173)
PEACH_PUFF = (255,218,185)
MISTY_ROSE = (255,228,225)
LAVENDER_BLUSH = (255,240,245)
LINEN = (250,240,230)
#OLD_LACE = (253,245,230)
PAPAYA_WHIP = (255,239,213)
SEA_SHELL = (255,245,238)
MINT_CREAM = (245,255,250)
SLATE_GRAY = (112,128,144)
LIGHT_SLATE_GRAY = (119,136,153)
LIGHT_STEEL_BLUE = (176,196,222)
LAVENDER = (230,230,250)
FLORAL_WHITE = (255,250,240)
ALICE_BLUE = (240,248,255)
GHOST_WHITE = (248,248,255)
HONEYDEW = (240,255,240)
IVORY = (255,255,240)
AZURE = (240,255,255)
SNOW = (255,250,250)
#BLACK = (0,0,0)
DIM_GREY = (105,105,105)
DIM_GRAY = (105,105,105)
GREY = (128,128,128)
GRAY = (128,128,128)
DARK_GREY = (169,169,169)
DARK_GRAY = (169,169,169)
SILVER = (192,192,192)
LIGHT_GREY = (211,211,211)
LIGHT_GRAY = (211,211,211)
GAINSBORO = (220,220,220)
WHITE_SMOKE = (245,245,245)
WARM_WHITE = (253, 245, 230)
#WHITE = (255,255,255)

RED = (255, 0, 0)
"""Red."""
YELLOW = (255, 150, 0)
"""Yellow."""
ORANGE = (255, 40, 0)
"""Orange."""
GREEN = (0, 255, 0)
"""Green."""
TEAL = (0, 255, 120)
"""Teal."""
CYAN = (0, 255, 255)
"""Cyan."""
BLUE = (0, 0, 255)
"""Blue."""
PURPLE = (180, 0, 255)
"""Purple."""
MAGENTA = (255, 0, 20)
"""Magenta."""
WHITE = (255, 255, 255)
"""White."""
BLACK = (0, 0, 0)
"""Black or off."""


GOLD = (255, 222, 30)
"""Gold."""
PINK = (242, 90, 255)
"""Pink."""
AQUA = (50, 255, 255)
"""Aqua."""
JADE = (0, 255, 40)
"""Jade."""
AMBER = (255, 100, 0)
"""Amber."""
OLD_LACE = (253, 245, 230)
"""Old lace or warm white."""

RGBW_WHITE_RGB = (255, 255, 255, 0)
"""RGBW_WHITE_RGB is for RGBW strips to illuminate only the RGB diodes."""
RGBW_WHITE_W = (0, 0, 0, 255)
"""RGBW_WHITE_W is for RGBW strips to illuminate only White diode."""
RGBW_WHITE_RGBW = (255, 255, 255, 255)
"""RGBW_WHITE_RGBW is for RGBW strips to illuminate the RGB and White diodes."""

RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
"""RAINBOW is a list of colors to use for cycling through.
Includes, in order: red, orange, yellow, green, blue, and purple."""

try:
    try:
        # Backwards compatibility for 5.3.0 and prior
        from _pixelbuf import colorwheel  # pylint: disable=unused-import
    except ImportError:
        from _pixelbuf import wheel as colorwheel  # pylint: disable=unused-import
except ImportError:

    def colorwheel(pos):
        """Colorwheel is built into CircuitPython's _pixelbuf. A separate colorwheel is included
        here for use with CircuitPython builds that do not include _pixelbuf, as with some of the
        SAMD21 builds. To use: input a value 0 to 255 to get a color value.
        The colours are a transition from red to green to blue and back to red."""
        if pos < 0 or pos > 255:
            return 0, 0, 0
        if pos < 85:
            return int(255 - pos * 3), int(pos * 3), 0
        if pos < 170:
            pos -= 85
            return 0, int(255 - pos * 3), int(pos * 3)
        pos -= 170
        return int(pos * 3), 0, int(255 - (pos * 3))


def calculate_intensity(color, intensity=1.0):
    """
    Takes a RGB[W] color tuple and adjusts the intensity.
    :param float intensity:
    :param color: color value (tuple, list or int)
    :return: color
    """
    # Note: This code intentionally avoids list comprehensions and intermediate variables
    # for an approximately 2x performance gain.
    if isinstance(color, int):
        return (
            (int((color & 0xFF0000) * intensity) & 0xFF0000)
            | (int((color & 0xFF00) * intensity) & 0xFF00)
            | (int((color & 0xFF) * intensity) & 0xFF)
        )

    if len(color) == 3:
        return (
            int(color[0] * intensity),
            int(color[1] * intensity),
            int(color[2] * intensity),
        )
    if len(color) == 4 and isinstance(color[3], float):
        return (
            int(color[0] * intensity),
            int(color[1] * intensity),
            int(color[2] * intensity),
            color[3],
        )
    return (
        int(color[0] * intensity),
        int(color[1] * intensity),
        int(color[2] * intensity),
        int(color[3] * intensity),
    )

blakebr
 
Posts: 139
Joined: Tue Apr 17, 2012 6:23 pm

Re: color.py update

by adafruit_support_mike on Tue Sep 14, 2021 9:00 pm

We've passed the information to Kattni, thanks!

blakebr wrote:Why is C o n f l i c t i n g a banned word?

Our automated spam filters catch words that correlate well to recent known spam, which leads to interesting results as the lists of 'optimized keywords' evolve. We think of it as a mini Turing test.

adafruit_support_mike
 
Posts: 63728
Joined: Thu Feb 11, 2010 2:51 pm

Re: color.py update

by blakebr on Tue Sep 14, 2021 9:18 pm

I hope I am smarter than Robby the Robot. ;-)
(Old movie)

blakebr
 
Posts: 139
Joined: Tue Apr 17, 2012 6:23 pm

Re: color.py update

by kattni on Wed Sep 15, 2021 1:15 pm

Hello Bruce,

This is quite the list! The color.py file was never meant to be an exhaustive list of colors, but I have no problem adding some new ones. 145 might be a bit much. :)

If you notice below each of the current colors, there is a docstring with the name of the color. This is required for documenting the color options. Our documentation builds from within the library code, which makes it easier to keep it updated, etc. So, to add all of the colors you listed, someone needs to go through and document all of the new ones before we can consider including it.

If you'd like to submit an update, please narrow it down to a more reasonable number, say, 20 more, and include the documentation lines below each tuple. Remember that with LEDs the difference between, for example, "maroon" and "dark red" isn't going to be obvious enough to matter. Also please do not include any colors (there are two in the list you provided) that reference or are related to Indigenous peoples as it would not be inclusive, and therefore against our Code of Conduct. I would suggest adding your new colors below " """Old lace or warm white."""" to add them to the list that includes GOLD, PINK, AQUA, etc.

If you're up for it, please consider submitting the updated list as a pull request to the Adafruit CircuitPython LED Animation GitHub repo(https://github.com/adafruit/Adafruit_Ci ... _Animation). If you're unfamiliar with Git and GitHub, there is a guide you can follow (https://learn.adafruit.com/contribute-t ... and-github). I'm happy to help with getting you spun up on Git/GitHub, and you can also join us on the Adafruit Discord (https://adafru.it/discord) to get help there. Otherwise, you can post an updated list here and I can get it added to the library.

Thanks!
Kattni

kattni
 
Posts: 121
Joined: Fri Aug 18, 2017 6:33 pm

Re: color.py update

by adafruit_support_carter on Wed Sep 15, 2021 1:19 pm

Why is C o n f l i c t i n g a banned word?

False triggering the word censor due to wild card matches. Should be fixed now.

adafruit_support_carter
 
Posts: 21400
Joined: Tue Nov 29, 2016 2:45 pm

Re: color.py update

by blakebr on Wed Sep 15, 2021 5:33 pm

Kattni,

Thank you for your pointers.
The attached code has been changed to comply with documentation requirements.
I did not cut down the list. The decisions were just too hard. Google "The Man Who Couldn’t Sort Potatoes"
Moccasin and Navajo_White have been removed.

Github and /discord may be on my dance card for the next time.

Bruce


Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_led_animation.color`
================================================================================

Color variables assigned to RGB values made available for import.

* Author(s): Kattni Rembor

Implementation Notes
--------------------

**Hardware:**

* `Adafruit NeoPixels <https://www.adafruit.com/category/168>`_
* `Adafruit DotStars <https://www.adafruit.com/category/885>`_

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
  https://circuitpython.org/downloads
"""

RED = (255, 0, 0)
"""Red."""
YELLOW = (255, 150, 0)
"""Yellow."""
ORANGE = (255, 40, 0)
"""Orange."""
GREEN = (0, 255, 0)
"""Green."""
TEAL = (0, 255, 120)
"""Teal."""
CYAN = (0, 255, 255)
"""Cyan."""
BLUE = (0, 0, 255)
"""Blue."""
PURPLE = (180, 0, 255)
"""Purple."""
MAGENTA = (255, 0, 20)
"""Magenta."""
WHITE = (255, 255, 255)
"""White."""
BLACK = (0, 0, 0)
"""Black or off."""

GOLD = (255, 222, 30)
"""Gold."""
PINK = (242, 90, 255)
"""Pink."""
AQUA = (50, 255, 255)
"""Aqua."""
JADE = (0, 255, 40)
"""Jade."""
AMBER = (255, 100, 0)
"""Amber."""
OLD_LACE = (253, 245, 230)
"""Old lace or warm white."""

ALICE_BLUE = (240,248,255)
"""ALICE_BLUE."""
ANTIQUE_WHITE = (250,235,215)
"""ANTIQUE_WHITE."""
AQUA_MARINE = (127,255,212)
"""AQUA_MARINE."""
AQUA_NEW = (0,255,255)
"""AQUA_NEW."""
AZURE = (240,255,255)
"""AZURE."""
BEIGE = (245,245,220)
."""BEIGE."""
BISQUE = (255,228,196)
"""BISQUE."""
BLUE_VIOLET = (138,43,226)
"""BLUE_VIOLET."""
BROWN = (165,42,42)
"""BROWN."""
BURLY_WOOD = (222,184,135)
"""BURLY_WOOD."""
CADET_BLUE = (95,158,160)
"""CADET_BLUE."""
CHART_REUSE = (127,255,0)
"""CHART_REUSE."""
CHOCOLATE = (210,105,30)
"""CHOCOLATE."""
CORAL = (255,127,80)
"""CORAL."""
CORN_FLOWER_BLUE = (100,149,237)
"""CORN_FLOWER_BLUE."""
CORN_SILK = (255,248,220)
"""CORN_SILK."""
CRIMSON = (220,20,60)
"""CRIMSON."""
DARK_BLUE = (0,0,139)
"""DARK_BLUE."""
DARK_CYAN = (0,139,139)
"""DARK_CYAN."""
DARK_GOLDEN_ROD = (184,134,11)
"""DARK_GOLDEN_ROD."""
DARK_GRAY = (169,169,169)
"""DARK_GRAY."""
DARK_GREEN = (0,100,0)
"""DARK_GREEN."""
DARK_GREY = (169,169,169)
"""DARK_GREY."""
DARK_KHAKI = (189,183,107)
"""DARK_KHAKI."""
DARK_MAGENTA = (139,0,139)
"""DARK_MAGENTA."""
DARK_OLIVE_GREEN = (85,107,47)
"""DARK_OLIVE_GREEN."""
DARK_ORANGE = (255,140,0)
"""DARK_ORANGE."""
DARK_ORCHID = (153,50,204)
"""DARK_ORCHID."""
DARK_RED = (139,0,0)
"""DARK_RED."""
DARK_SALMON = (233,150,122)
"""DARK_SALMON."""
DARK_SEA_GREEN = (143,188,143)
"""DARK_SEA_GREEN."""
DARK_SLATE_BLUE = (72,61,139)
"""DARK_SLATE_BLUE."""
DARK_SLATE_GRAY = (47,79,79)
"""DARK_SLATE_GRAY."""
DARK_TURQUOISE = (0,206,209)
"""DARK_TURQUOISE."""
DARK_VIOLET = (148,0,211)
"""DARK_VIOLET."""
DEEP_PINK = (255,20,147)
"""DEEP_PINK."""
DEEP_SKY_BLUE = (0,191,255)
"""DEEP_SKY_BLUE."""
DIM_GRAY = (105,105,105)
"""DIM_GRAY."""
DIM_GREY = (105,105,105)
"""DIM_GREY."""
DODGER_BLUE = (30,144,255)
"""DODGER_BLUE."""
FIREBRICK = (178,34,34)
"""FIREBRICK."""
FLORAL_WHITE = (255,250,240)
"""FLORAL_WHITE."""
FOREST_GREEN = (34,139,34)
"""FOREST_GREEN."""
FUCHSIA = (255,0,255)
"""FUCHSIA."""
GAINSBORO = (220,220,220)
"""GAINSBORO."""
GHOST_WHITE = (248,248,255)
"""GHOST_WHITE."""
GOLD_NEW = (255,215,0)
"""GOLD_NEW."""
GOLDEN_ROD = (218,165,32)
"""GOLDEN_ROD."""
GRAY = (128,128,128)
"""GRAY."""
GREEN = (0,128,0)
"""GREEN."""
GREEN_YELLOW = (173,255,47)
"""GREEN_YELLOW."""
GREY = (128,128,128)
"""GREY."""
HONEYDEW = (240,255,240)
"""HONEYDEW."""
HOT_PINK = (255,105,180)
"""HOT_PINK."""
INDIGO = (75,0,130)
"""INDIGO."""
IVORY = (255,255,240)
"""IVORY."""
KHAKI = (240,230,140)
"""KHAKI."""
LAVENDER = (230,230,250)
"""LAVENDER."""
LAVENDER_BLUSH = (255,240,245)
"""LAVENDER_BLUSH."""
LAWN_GREEN = (124,252,0)
"""LAWN_GREEN."""
LEMON_CHIFFON = (255,250,205)
"""LEMON_CHIFFON."""
LIGHT_BLUE = (173,216,230)
"""LIGHT_BLUE."""
LIGHT_CORAL = (240,128,128)
"""LIGHT_CORAL."""
LIGHT_CYAN = (224,255,255)
"""LIGHT_CYAN."""
LIGHT_GOLDEN_ROD_YELLOW = (250,250,210)
"""LIGHT_GOLDEN_ROD_YELLOW."""
LIGHT_GRAY = (211,211,211)
"""LIGHT_GRAY."""
LIGHT_GREEN = (144,238,144)
"""LIGHT_GREEN."""
LIGHT_GREY = (211,211,211)
"""LIGHT_GREY."""
LIGHT_PINK = (255,182,193)
"""LIGHT_PINK."""
LIGHT_SALMON = (255,160,122)
"""LIGHT_SALMON."""
LIGHT_SEA_GREEN = (32,178,170)
"""LIGHT_SEA_GREEN."""
LIGHT_SKY_BLUE = (135,206,250)
"""LIGHT_SKY_BLUE."""
LIGHT_SLATE_GRAY = (119,136,153)
"""LIGHT_SLATE_GRAY."""
LIGHT_STEEL_BLUE = (176,196,222)
"""LIGHT_STEEL_BLUE."""
LIGHT_YELLOW = (255,255,224)
"""LIGHT_YELLOW."""
LIME = (0,255,0)
"""LIME."""
LIME_GREEN = (50,205,50)
"""LIME_GREEN."""
LINEN = (250,240,230)
"""LINEN."""
MAGENTA_NEW = (255,0,255)
"""MAGENTA_NEW."""
MAROON = (128,0,0)
"""MAROON."""
MEDIUM_AQUA_MARINE = (102,205,170)
"""MEDIUM_AQUA_MARINE."""
MEDIUM_BLUE = (0,0,205)
"""MEDIUM_BLUE."""
MEDIUM_ORCHID = (186,85,211)
"""MEDIUM_ORCHID."""
MEDIUM_PURPLE = (147,112,219)
"""MEDIUM_PURPLE."""
MEDIUM_SEA_GREEN = (60,179,113)
"""MEDIUM_SEA_GREEN."""
MEDIUM_SLATE_BLUE = (123,104,238)
"""MEDIUM_SLATE_BLUE."""
MEDIUM_SPRING_GREEN = (0,250,154)
"""MEDIUM_SPRING_GREEN."""
MEDIUM_TURQUOISE = (72,209,204)
"""MEDIUM_TURQUOISE."""
MEDIUM_VIOLET_RED = (199,21,133)
"""MEDIUM_VIOLET_RED."""
MIDNIGHT_BLUE = (25,25,112)
"""MIDNIGHT_BLUE."""
MINT_CREAM = (245,255,250)
"""MINT_CREAM."""
MISTY_ROSE = (255,228,225)
"""MISTY_ROSE."""
NAVY = (0,0,128)
"""NAVY."""
OLIVE = (128,128,0)
"""OLIVE."""
OLIVE_DRAB = (107,142,35)
"""OLIVE_DRAB."""
ORANGE_NEW = (255,165,0)
"""ORANGE_NEW."""
ORANGE_RED = (255,69,0)
"""ORANGE_RED."""
ORCHID = (218,112,214)
"""ORCHID."""
PALE_GOLDEN_ROD = (238,232,170)
"""PALE_GOLDEN_ROD."""
PALE_GREEN = (152,251,152)
"""PALE_GREEN."""
PALE_TURQUOISE = (175,238,238)
"""PALE_TURQUOISE."""
PALE_VIOLET_RED = (219,112,147)
"""PALE_VIOLET_RED."""
PAPAYA_WHIP = (255,239,213)
"""PAPAYA_WHIP."""
PEACH_PUFF = (255,218,185)
"""PEACH_PUFF."""
PERU = (205,133,63)
"""PERU."""
PINK_NEW = (255,192,203)
"""PINK_NEW."""
PLUM = (221,160,221)
"""PLUM."""
POWDER_BLUE = (176,224,230)
"""POWDER_BLUE."""
PURPLE_NEW = (128,0,128)
"""PURPLE_NEW."""
ROSY_BROWN = (188,143,143)
"""ROSY_BROWN."""
ROYAL_BLUE = (65,105,225)
"""ROYAL_BLUE."""
SADDLE_BROWN = (139,69,19)
"""SADDLE_BROWN."""
SALMON = (250,128,114)
"""SALMON."""
SANDY_BROWN = (244,164,96)
"""SANDY_BROWN."""
SEA_GREEN = (46,139,87)
"""SEA_GREEN."""
SEA_SHELL = (255,245,238)
"""SEA_SHELL."""
SIENNA = (160,82,45)
"""SIENNA."""
SILVER = (192,192,192)
"""SILVER."""
SKY_BLUE = (135,206,235)
"""SKY_BLUE."""
SLATE_BLUE = (106,90,205)
"""SLATE_BLUE."""
SLATE_GRAY = (112,128,144)
"""SLATE_GRAY."""
SNOW = (255,250,250)
"""SNOW."""
SPRING_GREEN = (0,255,127)
"""SPRING_GREEN."""
STEEL_BLUE = (70,130,180)
"""STEEL_BLUE."""
TAN = (210,180,140)
"""TAN."""
TEAL_NEW = (0,128,128)
"""TEAL_NEW."""
THISTLE = (216,191,216)
"""THISTLE."""
TOMATO = (255,99,71)
"""TOMATO."""
TURQUOISE = (64,224,208)
"""TURQUOISE."""
VIOLET = (238,130,238)
"""VIOLET."""
WARM_WHITE = (253, 245, 230)
"""WARM_WHITE."""
WHEAT = (245,222,179)
"""WHEAT."""
WHITE_SMOKE = (245,245,245)
"""WHITE_SMOKE."""
YELLOW_GREEN = (154,205,50)
"""YELLOW_GREEN."""
YELLOW_NEW = (255,255,0)
"""YELLOW_NEW."""

RGBW_WHITE_RGB = (255, 255, 255, 0)
"""RGBW_WHITE_RGB is for RGBW strips to illuminate only the RGB diodes."""
RGBW_WHITE_W = (0, 0, 0, 255)
"""RGBW_WHITE_W is for RGBW strips to illuminate only White diode."""
RGBW_WHITE_RGBW = (255, 255, 255, 255)
"""RGBW_WHITE_RGBW is for RGBW strips to illuminate the RGB and White diodes."""

RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
"""RAINBOW is a list of colors to use for cycling through.
Includes, in order: red, orange, yellow, green, blue, and purple."""

try:
    try:
        # Backwards compatibility for 5.3.0 and prior
        from _pixelbuf import colorwheel  # pylint: disable=unused-import
    except ImportError:
        from _pixelbuf import wheel as colorwheel  # pylint: disable=unused-import
except ImportError:

    def colorwheel(pos):
        """Colorwheel is built into CircuitPython's _pixelbuf. A separate colorwheel is included
        here for use with CircuitPython builds that do not include _pixelbuf, as with some of the
        SAMD21 builds. To use: input a value 0 to 255 to get a color value.
        The colours are a transition from red to green to blue and back to red."""
        if pos < 0 or pos > 255:
            return 0, 0, 0
        if pos < 85:
            return int(255 - pos * 3), int(pos * 3), 0
        if pos < 170:
            pos -= 85
            return 0, int(255 - pos * 3), int(pos * 3)
        pos -= 170
        return int(pos * 3), 0, int(255 - (pos * 3))


def calculate_intensity(color, intensity=1.0):
    """
    Takes a RGB[W] color tuple and adjusts the intensity.
    :param float intensity:
    :param color: color value (tuple, list or int)
    :return: color
    """
    # Note: This code intentionally avoids list comprehensions and intermediate variables
    # for an approximately 2x performance gain.
    if isinstance(color, int):
        return (
            (int((color & 0xFF0000) * intensity) & 0xFF0000)
            | (int((color & 0xFF00) * intensity) & 0xFF00)
            | (int((color & 0xFF) * intensity) & 0xFF)
        )

    if len(color) == 3:
        return (
            int(color[0] * intensity),
            int(color[1] * intensity),
            int(color[2] * intensity),
        )
    if len(color) == 4 and isinstance(color[3], float):
        return (
            int(color[0] * intensity),
            int(color[1] * intensity),
            int(color[2] * intensity),
            color[3],
        )
    return (
        int(color[0] * intensity),
        int(color[1] * intensity),
        int(color[2] * intensity),
        int(color[3] * intensity),
    )

blakebr
 
Posts: 139
Joined: Tue Apr 17, 2012 6:23 pm

Re: color.py update

by kattni on Thu Sep 16, 2021 1:44 pm

Bruce,

Thanks for the update! It'll be a bit before I can sit down and narrow it down for addition, but I've copied your file, and put the task on my to-do list. I appreciate the effort you put in! No worries on not being up for GitHub yet, it can be overwhelming.

Keep an eye out for the color update in the next week or so, I hope.

Cheers,
Kattni

kattni
 
Posts: 121
Joined: Fri Aug 18, 2017 6:33 pm

Re: color.py update

by blakebr on Thu Sep 16, 2021 2:03 pm

Kattni,

Absolutely no rush on this.
I figured you would look at it when 2:30AM is on the clock and you need something to do to put you to sleep and you have run out of wine. I am good with that.

Bruce

blakebr
 
Posts: 139
Joined: Tue Apr 17, 2012 6:23 pm

Please be positive and constructive with your questions and comments.