In Physics 101, we learn that color is
one-dimensional . A color can be described by just one number, the frequency of the light. When light passes through a prism, or a raindrop, the angle of refraction depends on the frequency, which gives us the rainbow.
In Programming 101, we learn that color is three-dimensional. A color requires three numbers for its description, a red value, a green value and a blue value. You can think of colors as being graphed with x, y and z co-ordinates. LCD screens, web pages and digital cameras are all based on this three-dimensional model.
Alternatively, in Biology 101, we learn that the human eye has three kinds of color receptors, corresponding more or less to red, green and blue. We can see that the computer model is based on the biological model, not the physical model.
So how do we map a one-dimensional spectrum to a three-dimensional grid? The picture above is my first attempt. Not very rainbowish, is it? (I'm trying to find a mathematical formula that I can program to generate a rainbow graphic.)
The mismatch between models leads to some weird anomalies. For example, there really is such a thing as yellow light, but the yellow on your computer screen is a mixture of red and green. Your computer screen doesn't have any yellow in it.
On the other hand, there is no such thing as purple light. We think of purple as being half way between red and blue, but red and blue are at opposite ends of the spectrum, so there is no half way between. There really is a violet, on the far side of blue, but violet is not the same as purple. In physics, that is. In computers, both purple and violet are made by mixing red and blue.
It's an interesting mess. I'm trying to see it as more of an opportunity than a problem. I'll go with the three-dimensional model, because that's what my computer tools use. If I can't generate realistic rainbows, I'll generate alien rainbows, with the colors in the wrong order.