# How can I mix colors?

As far as I know if you combine Blue and Green the result is Cyan (using additive mixing). I would like to know some basic arithmetic of colors for making a Mathematica game for kids (using colored numbers).

My problem is what is the result of mixing $2\times Blue + 1\times Cyan$?

Or consider a more complicated example: $3\times Red + 2\times Green + 2\times Blue$.

Is this color arithmetic the same for subtractive and additive mixing?

RGBColor[{red channel, green channel, blue channel}] defines a color. Here is a didactic example of this:

mix[r_, g_, b_] := If[Max[{r, g, b}] > 0, RGBColor[{r, g, b}/Max[{r, g, b}]], RGBColor[{0, 0, 0}]]
Manipulate[
Graphics[{
mix[r, g, b],
Rectangle[]
}],
{r, 0, 100, 1}, {g, 0, 100, 1}, {b, 0, 100, 1}
]


{r,g,b} has been normalized so that the largest component is 1, because values larger than 1 are clipped by Mathematica.

For your complicated example, you simply have to write RGBColor[{3,2,5}/5].

Try typing Cyan into Mathematica. It will return RGBColor[0, 1, 1]. So the result of mixing 2 X blue plus 1 X cyan is RGBColor[(2 {0, 0, 1} + {0, 1, 1})/3].

Mathematica helps you mix colors with the function Blend. For example Blend[{Blue, Cyan}, 1/3] returns RGBColor[0, 1/3, 1] which is exactly what the computation above returns.

There is also CMYKColor which works the same way, but instead of specifying red, green and blue components we specify cyan, magenta, yellow and black.

• And to answer the second part of the OP's question, this is additive mixing. Oct 24 '13 at 0:46
• Your mix can be written shorter with RGBColor @@ Normalize[{r,g,b}, Max] :)
– Kuba
Oct 24 '13 at 10:52
• @Kuba Nice, I didn't know about the second argument. Oct 24 '13 at 13:00