circuitpython-tricks icon indicating copy to clipboard operation
circuitpython-tricks copied to clipboard

Rainbowio.colorwheel does not return a tuple

Open Neradoc opened this issue 1 year ago • 1 comments

There's a mistake in the Neopixels / Dotstars section where colorwheel is stated to return a tuple, but in reality it returns a 0xRRGGBB int. That text is also mirrored in the learn guide.

The colorwheel() function takes a single value 0-255 hue and returns an (R,G,B) tuple given a single 0-255 hue.

By the way, when I need to convert into a tuple, I found that one-line trick so I don't have to use bitwise operations and stuff. (You don't need the tuple conversion to index into it).

>>> tuple((0xFF8000).to_bytes(3,"big"))
(255, 128, 0)
>>> tuple(colorwheel(32).to_bytes(3,"big"))
(159, 96, 0)
>>> [x // 2 for x in (0xFF8000).to_bytes(3,"big")]
[127, 64, 0]

Neradoc avatar Jul 17 '22 11:07 Neradoc

Ahh, yes. Thank you! I'll update that section shortly.

And cool tuple tip! I will steal that too (with attribution) :)

todbot avatar Jul 17 '22 18:07 todbot

fixed, forgot to close

todbot avatar Jun 13 '23 18:06 todbot