Recommended Posts

xiajia    163

Description of the problem are as follows:
the first color1(c1) RGB value is rgb1,
the second color2(c2) RGB value is rgb2,
How to calculate the RGB(rgb3) of the color3(c3) mixed with c1 and c2,the mixing ratio is x: y.
For example:red and green 1:1 mixture is yellow, red and black 1:1 mixture is dark red.

Share on other sites

c3 = (xc1 + yc2) / (x+y)

(for each component, and you will need to cast each component to a float or int before converting back to unsigned char. You probably want to round the values as well, but I'll leave that as an exercise since it smells like homework anyway).

EDIT: Note that in the red/green example, you will end up with the r and g compoinents at half intensity. If you need to keep the intensity the same, you'll need to do something to adjust the luminance as well...)

Share on other sites
Crusable77    594

Just an idea, however you can make a function that takes the two colors and then the ratios like this:

struct Color{

Int R, G, B;
};

Color GetColorFromRatio(Color c1, Color c2, unsigned int Ratio1, unsigned int Ratio2);


Now in the function you would use some crazy math to get the ratios and create your new color. I am not sure of the math and if this is the best way to do it (or if this will work) but this is just an idea.

Edited by Crusable

Share on other sites
xiajia    163

Thanks for Paradigm Shifter and Crusable, i get a lot of tips.I have found a good method based on CMYK. Although there are still some problems, but has almost.

Create an account

Register a new account