This just came up sorta in another thread and I’ll come back to it but I wanted to save this tidbit:
https://www.easyrgb.com/en/math.php
Conversion from many (including HSV, RGB, hsl, cmyk) to many others
Added: Another good resource
So color blending…
The “right” way to do color blending in LEDs is via RGB:
R+G is Yellow, etc…
See Physics Tutorial: Color Addition
But… that’s pretty counter to what people ‘think’ color mixing is like…
also
Computer RGB values are derived from the square root of photon flux. So as a general function, your math should take that into account. The general function for this for a given channel is:
blendColorValue(a, b, t)
return sqrt((1 - t) * a^2 + t * b^2)
Where a and b are the color values to blend, and t is a number from 0-1 representing the point in the blend you want between a and b.
If you want to do it cheaper, the average of the two values is usually fine…
aka (a+b)/2
doesn’t factor in Alpha (mixing vs blending depends on Alpha), or gamma correction…
http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/
then we have Wikipedia:
Which is more than we need to deal with, but ‘Screen’ is basically a blend where it’s more like turning on both lights, rather than changing one light.
So if I mixed a dark red and a dark green, if it’s a “mix” blend, it would be a yellow at the same brightness… if it’s a ‘screen’ blend, it would be brighter yellow, which actually makes sense in some LED contexts… if I had spinning red ring and a spinning green ring, both at (for example) .5 brightness, when they overlap, do I want the yellow bit to be the same brightness at .5, or would I want it to be brighter (like 2 light sources overlapping)?
Screen itself is easy, it’s screen(a,b)=1-(1-a)(1-b)
(again, per channel),
In the case of RGB pixels, Red and Green, with no overlap, I’m not sure it would do what I say above… you’d end up with R at .5 and G at .5 so Yellow at .5 on both, which might not look as bright as expected? Gamma correction?
Sounds like I’m gonna have to write some library code