Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


about color mix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 xiajia   Members   -  Reputation: 163

Like
0Likes
Like

Posted 06 April 2013 - 06:43 AM

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.



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5439

Like
1Likes
Like

Posted 06 April 2013 - 11:26 AM

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, 06 April 2013 - 11:39 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 Crusable   Members   -  Reputation: 594

Like
0Likes
Like

Posted 06 April 2013 - 11:34 AM

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, 06 April 2013 - 11:35 AM.


#4 xiajia   Members   -  Reputation: 163

Like
0Likes
Like

Posted 08 April 2013 - 07:11 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS