When I was a kid, my teacher told us that the primary colors were red, yellow, and blue. What she didn’t tell me was…
As I mentioned in an earlier column, I’m currently having a lot of fun with my Awesome 12 x 12 Ping Pong Ball Array. As I also mentioned, I’ve been documenting the ongoing development of this project in in my monthly Cool Beans and Programming Tips and Tricks columns in Practical Electronics (PE), which is the UK’s premier electronics, computing, hobbyist, and maker magazine (PE is available around the world in both print and digital formats).
In the September 2020 issue of PE, which — due to the vagaries of print publishing — will hit the streets in the first week of August, we visualize the array as laying flat on the floor with drips of virtual water falling on it from above.
We start with individual drips lighting their associated pixels (ping pong balls) with white light one at a time. The way we implement this algorithm, each drip appears in a random location, turns hard on, and then turns hard off again. The duration of each drip is random, as is the inter-drip delay (i.e., the delay between adjacent drips).
As an aside, while I’m thinking about it, I should perhaps mention that you can see videos of all of this in action on the Cool Beans YouTube Channel (make sure to tell your friends LOL).
Next, I decided to light the drips up with random colors, but which colors should we use? Theoretically, since each pixel has red, green, and blue color channels, each of which can have 2^8 = 256 values numbered from 0 to 255, we can achieve 2^24 = 256 x 256 x 256 = 16,777,216 different hues, shades, tints, and tones.
In practice, however, we want to use a small subset of colors that are as bright and vibrant as possible. This leads us to the topic of primary colors. When I was a kid, my teacher told us that the primary colors were red, yellow, and blue, and that we could make other colors by mixing these primaries (red + yellow = orange, blue + yellow = green, and red + blue = purple).
What she didn’t tell us is that this is just one set of primaries, and that term “primary colors” simply refers to any collection of three or more colors that can be combined to form a gamut of other colors. I only came to understand this much later when I learned that printers use cyan (C), magenta (M), and yellow (Y) inks as their primary colors.
Furthermore, inks, paints, and pigments are subtractive in nature. The way I think of this is that we start off with a white canvas in white light. When we daub one of our primary colors on the paper, it absorbs some of the frequencies from the white light and reflects the rest, and it’s these reflected frequencies that we see. When we merge primaries, they each absorb their own frequencies, and all we see are the leftovers (yellow + magenta = red, magenta + cyan = blue, and cyan + yellow = green). When all of the primaries are mixed, they absorb all of the frequencies, leaving us with black.
By comparison, in the case of light, the primary colors with which we are most familiar are red, green, and blue, and these act in an additive manner. The way I think of this is to start off in a dark room and then turn on floodlights featuring the additive primaries. In this case, red + green = yellow, green + blue = cyan, and red + blue = magenta. When all of the additive primaries are mixed, we perceive the result as white light.
One way to represent colors is to use a color wheel. There are myriad representations out there in cyberspace, but I must admit to being rather proud of the one I created and the information it conveys. As we see, we can mix our three primary colors (red green and blue) to generate three secondary colors (yellow, cyan, and magenta) and six tertiary colors (flush orange, chartreuse, spring green, azure, electric indigo, and rose).
The 0 to 11 annotations reflect the way I index these values in an array in my programs. Given a random color value, these numbers allow me to quickly determine things like that color’s complementary, split complementary, triadic, and analogous counterparts.
Speaking of which, in the October issue of PE, we are going to create some functions that allow us to fade from one color value to another. This isn’t as complex as a beginner might fear, but it does have its subtleties, and we do have to treat the red, green, and blue channels independently. Later, in the November issue of PE, we are going to take the initial randomly determined color of each drip, and — in a series of small programs — experiment with fading to that color’s various complementary etc. counterparts.
All of these experiments are going to prove useful when we come to determine what colors we wish to use when we implement more sophisticated programs, like displaying scrolling text messages and implementing Conway’s Game of Life. But all of these will be the topics of future columns. In the meantime, as always, I welcome your comments, questions, and suggestions.