• Advertisement
Sign in to follow this  

about color mix

This topic is 1751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement

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...)

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites

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 this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement