todbot / circuitpython-tricks

Some CircuitPython tricks, mostly reminders to myself
MIT License
577 stars 65 forks source link

Rainbowio.colorwheel does not return a tuple #7

Closed Neradoc closed 1 year ago

Neradoc commented 1 year ago

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]
todbot commented 1 year ago

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

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

todbot commented 1 year ago

fixed, forgot to close