3
$\begingroup$

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?

$\endgroup$
8
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.