# RGB... wait, but why?

Hi folks,

I just always get confused about the RGB color coding. At school, I learned about the primary colors red, yellow and blue, and how when you mix them, you get the secondary colors. Playing around with watercolors that seemed to be true. Wait, and now when coding we have suddenly red, green and blue? Why is that? Also, I noticed, in the print cartridge we have cyan, magenta and yellow. Anybody having a scientific explanation for this?

1 Like

RGB is an additive colour model (if you add a red, green and a white light together you get white). Itâ€™s how your eye works: you have R, G and B cones and they work together to allow the brain to see different colours, each one reacting to light at given wavelengths.

Adding any two R/G/B colours together gives you one of the three in the subtractive colour model. Removing all of them gives you black (ie there is no light).

Red Yellow and Blue (or more properly Cyan, Magenta and Yellow) are used in subtractive colour models, theyâ€™re used for print media (and paints) and describe how colour works when you pass white light through [microscopic] layers of another medium (eg paper). Subtractive because when you take away colours, the base colour goes towards transparent (if there is no colour applied, then there is no colour). When you add them together, the colour goes towards black.

Historically, RYB is how itâ€™s been described (historically as in 100s-1000s of years), so even though CMY is more versatile, RYB has hung around. RYB/CMY is also easy to explain visually because you can just chuck some paint on paper to demonstrate it (whereas you need lights to demonstrate RGB).

In all models the above explains why black and white arenâ€™t colours. In RGB, white is just a full spectrum of light rather than individual colours, black is no light. In CMY, white is no colour [on a white background], and you canâ€™t ever actually get to what youâ€™d consider real black (you can just get a perceptually very dark colour by managing to get to something that reflects the smallest possible amount of light).

Note these are all somewhat arbitrary models for describing colour, and there are a lot of different variations on these colour models. But the subtractive colour model (the one you get taught in school) only really applies to stuff like painting/printing (which admittedly includes a vast amount of stuff). With electronic devices, youâ€™re looking at a light source (think of each pixel as three lights, one each of red green and blue), it makes sense to describe it using an additive colour model.

Edit: printed stuff is restricted in the number of colours you can use (just actual physical constraints). Computer graphics nowadays are much less restricted, you can go up to billions of different colours. Which means there are lots of colours that can be rendered on a computer screen that you canâ€™t print. So when working professionally in graphics software, you would normally switch from RGB-based model to a CYM model if designing for print (or you would pick specific colours from a PantoneÂ© palette).

Side note: RGB and the other additive colour models are all ever so slightlyâ€¦wrong I guessâ€¦in various ways in various circumstances: theyâ€™re a way to mathematically encode colour, and problems appear in when you try to do calculations with them (for example, if I try to make a gradient from one colour to another using RGB, itâ€™s quite common to end up with a big grey area in the middle which is never what I want). I suppose this happens with subtractive colour as well (think how easy it is to make a horrible brown colour by accident when youâ€™re mixing paints)

11 Likes

Wow, that was a pretty extensive explanation! Interesting! Now every thing makes more sense. I am wondering, what else do I not know, all the time since I embarked on this coding journey. Thank you for taking the time

2 Likes

its not like art class. Think colors of the pixels on an old TV

1 Like

For the record, RYB isnâ€™t wrong or outdated. While also a subtractive color model, it works better for opaque pigment than CMYK, which is based on transparent dyes:
https://www.quora.com/In-theory-the-RYB-color-model-achieves-a-smaller-gamut-than-CMY-Why-is-a-CMY-based-color-palette-not-popular-in-painting

That said, we generally code color for screens (RGB) and print (CMYK), not painting

2 Likes