When mixing blue and yellow paint, the result is some sort of green.
I have two rgb colors:
blue = (0, 0, 255)
and yellow = (255, 255, 0)
What is the algorithm for finding the rgb color that is the result of mixing the two colors, as they would appear when using paint? The resulting colors from the algorithm does not have to be terribly exact. For the example above it would only have to look like some sort of green.
Thanks in advance.
Edit: This function, written in Go, worked for me, based on the answer from LaC.
func paintMix(c1, c2 image.RGBAColor) image.RGBAColor {
r := 255 - ((255 - c1.R) + (255 - c2.R))
g := 255 - ((255 - c1.G) + (255 - c2.G))
b := 255 - ((255 - c1.B) + (255 - c2.B))
return image.RGBAColor{r, g, b, 255}
}
Edit #2 Allthought this manages to mix cyan and yellow, the mix between blue and yellow becomes black, which doesn't seem right. I'm still looking for a working algorithm.
Edit #3 Here's a complete working example in Go, using the HLS colorspace: http://go.pastie.org/1976031. Thanks Mark Ransom.
Edit #4 It seems like the way forward for even better color mixing would be to use the Kubelka-Munk equation
You wanna use subtractive CMY-colors (Cyan, Magenta, Yellow) (as LaC is doing, whithout using the term)
The conversion back and forth is simple: (C,M,Y) = (-R,-G,-B).
So CMY(0,0,0) is white and CMY(FF,FF,FF) is black.
When you add two CMY colors, there are different ways to calculate the new values. You can take the average, max or something in between for each color value.
Eg. for light-filters you always use the max value. For paint you properly want to use, something closer to the average value.
As LaC points out, you don't get green from mixing yellow and blue, but from mixing yellow and cyan. Yellow and blue actually gives black, when mixing by max value (eg. light filters). This is why, you might want to use something closer to the average value for paint mixing.
You don't wanna use CMYK, unless you want to print something. The black "K" color is primarily used in printers to save ink, but it's not needed to represent colors.
The colour space RBG is based on light emission, the colour space of dyes and pigments is based on light absorption.
e.g. Plant's don't look green because they emit green light, but because they absorb all the other colours of light, reflecting only green.
Based on this, you should be able to get pretty close by doing a conversion from RGB to an absorptive colour space, doing the "mix" and then back again.
Paint works by absorption. You start with white light (255,255,255) and multiply it by the absorption factors.
Blue paint absorbs all red and green light that hits it.
Yellow paint absorbs all blue light that hits it.
In a perfect world, that means that combining yellow and blue paint would result in black paint, or at best a muddy gray. In practice the "blue" paint has a bias towards green, so you get a muddy green. I've never seen an example of mixing yellow and blue that produces a satisfactory green. Wikipedia goes into some of the complexities of this process: http://en.wikipedia.org/wiki/Primary_color#Subtractive_primaries
I think what you are really asking is how to interpolate colors along a color wheel. This should be independent of whether the colors are absorptive as in paint, or emissive as in RGB displays.
Edit: By working in the HSL color space you can get the kind of results you're looking for. Here's some code in Python that implements the algorithm; averaging hues is tricky, and is based on a previous answer of mine for averaging angles.
Note that this answer does not emulate paint mixing, for the reasons stated above. Rather it gives an intuitive mixing of colors that is not grounded in any physical world reality.
Actually, you get green from mixing (subtractively) yellow and cyan. Yellow is red + green (255, 255, 0), cyan is green + blue (0, 255, 255). Now make their opposite colors: blue (0, 0, 255) and red (255, 0, 0). Mix them additively and you get purple (255, 0, 255). Make its opposite and you get green (0, 255, 0).
In other words, you can get a subtractive mix as the opposite of the additive mix of the opposites of your two colors.
Use Convert::Color to produce this sort of output:
When running this sort of code: