jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Colour Mixing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Colour Mixing" Watch "Colour Mixing" New topic

Colour Mixing

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hi, I want to be able to mix colours...

I tried to do it by averaging out the components, but this doesn't work, eg R+G+B = WHITE.

Thers a thing called subtractive colour mixing, but all the examples I've seen don't give you the numbers.

I want to be able to mix say rgb=(100,200,150) with rgb=(50,60,70) and get the same result you would as when mixing paint.

Can anyone help?

Peter van de Riet
Ranch Hand

Joined: Apr 09, 2004
Posts: 112

For mixing paint I think you have to take the average of the colors:
((100,200,150) + (50,60,70)) / 2 = (75, 130, 110)

BTW: mixing paint is NOT the same as mixing light like 255,0,0 (red) + 0,255,0 (green) + 0,0,255 (blue) = 255,255,255 (white)
try it yourself: take the 3 colors paint (red green blue) and paint 3 parts of a circle each with a different color, then spin the circle (using a pencil)
take the same colors and mix then with same amounts, you won't get the same color as with spinning the circle.

Each number system has exactly 10 different digits.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Thanks, but I don't think its that simple.

Eg Green = (0,255,0) and Magenta = (255,0,255)
So they are opposite corners of the colour cube.

But when you average them out you get (127,127,127) which is a medium gray.

I might be wrong, but mixing green and magenta paint, I would not expect it to come out gray.

Any thought(s) ?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
From Additive color:

Results obtained when mixing additive colors are often counterintuitive for people accustomed to the more everyday subtractive color system of pigments, dyes, inks and other substances which present color to the eye by reflection rather than emission.

Also see Color mixing and Subtractive color.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
I figured it was subtractive colour but nothing seems to explain the math needed to do it.

Supposing I have 2 CMY or CMYK colours, how can I do the 'subtraction' ?

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

The last page of this PDF contains C source code for conversion of paint mixing into RGB colors:
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Thanks, so I've translated the code to java..

I'm able to convert any ryb colour into rgb colour (using the cubic interpolation)

So regarding mixing colours..
If I wanted to mix ryb1 with ryb2, would I just average out the ryb components...
ryb3 = ((r1+r2)/2, (y1+y2)/2, (b1+b2)/2), and then convert ryb3 to rgb to be displayed?

I agree. Here's the link: http://aspose.com/file-tools
subject: Colour Mixing
It's not a secret anymore!