Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
1  
And to answer the second part of the OP's question, this is additive mixing. –  bobthechemist 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. –  Pickett Oct 24 '13 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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