rainbowio.colorwheel returning RGB tuples

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
RoseNose
 
Posts: 17
Joined: Thu Jan 25, 2018 2:50 pm

rainbowio.colorwheel returning RGB tuples

Post by RoseNose »

Hey,
I've just spent a frustrating hour and a half trying to figure out how rainbowio.colorwheel returns color values. I was trying to split the int returned into 3 bytes for standard (R,B,G) palette shading. I managed to get it to work after realizing that it didn't return leading 0s (as in (0,255,255) returned as 0xFFFF instead of 0x00FFFF). The main reason this was frustrating is that I couldn't find documentation for rainbowio *anywhere* not in the lib downloads, not on git, not on your 'Learn' page, nowhere. It would be a huge help to have the 'built-in' libraries somewhere accessible if for no other reason than to grok what they do.
For anyone interested in how I solved my issue:

Code: Select all

def rgb_from_hex(h):
    hexa = hex(colorwheel(h))[2:]
    while len(hexa) < 6:
        hexa = '0' + hexa
    r = int(hexa[0:2], 16)
    g = int(hexa[2:4], 16)
    b = int(hexa[4:6], 16)
    return (r, g, b)

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: rainbowio.colorwheel returning RGB tuples

Post by danhalbert »

The documentation for built-in modules is here: https://circuitpython.org/, then click on the "Documentation" link at the top of the page.
Or, more directly: https://circuitpython.readthedocs.io/

It's a problem we need to fix that the documentation is not linked more places. Where did you look for a documentation link, and where would you hope to find one? We would like to add links in places are trying to look. Thanks for your suggestions.

A different and faster way to extract the RGB values is to use bit manipulation of the integer value. This code shifts the value appropriately and then zeros out all but the lower 8 bits for each color:

Code: Select all

r = (h >> 16) & 0xff
g = (h >> 8) & 0xff
b = h & 0xff

User avatar
RoseNose
 
Posts: 17
Joined: Thu Jan 25, 2018 2:50 pm

Re: rainbowio.colorwheel returning RGB tuples

Post by RoseNose »

That chunk of code looks so much cleaner, thank you! First place I checked was the master lib download folder (maybe add a README?) then I went to git which is where I can usually find details on your various libraries, then I checked your Learn page, and finally I just started googling. I did end up on readthedoc, but this is the entirety of the entry on rainbowio:
rainbowio
rainbowio module.

Provides the colorwheel() function.

Available on these boards
rainbowio.colorwheel(n: float) → int
C implementation of the common colorwheel() function found in many examples. Returns the colorwheel RGB value as an integer value for n (usable in neopixel and dotstar).
I would recommend a hook on the main CircuitPython master guide, and a README in the master lib download. Its often hard to know just what all is available and I don't even think I've even seen a comprehensive list of the built in modules. Thanks for your response the work yall do maintaining this code.

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: rainbowio.colorwheel returning RGB tuples

Post by danhalbert »

BTW, the "Welcome to CircuitPython" guide is being revised and restructured as we speak, and will include an explicit "CircuitPython Documentation" page, with links to various documentaion.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”