Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey Codeproject,

I'm wondering how you blend two colors like you would with paint in real life. For instance, blending red and blue would result in purple. I'm wondering this because I'd also like the opacity of the color to play in as a component (meaning that if the alpha is 255 it would blend harder than it if it wouldn't.)

To clarify, [Here's] a picture of what I want to be able to do.

C#
public Color PaintBlendColors(Color One, Color Two)
{
   Color Col;
   /*Col = Blend?*/
   return Col;
}


Best Regards,
- Edz

What I have tried:

I've so far tried using a pre-build function in Monogame/XNA called Color.Lerp, but this does not give the desired effect.
Posted
Updated 2-Dec-20 11:53am

1 solution

You can try to calc the mean of the 2 colors
C#
Col.Red= (One.Red+ Two.Red)/ 2;
...
 
Share this answer
 
Comments
Member 11841791 13-Aug-16 8:06am    
Combining red and yellow to get orange doesn't work that way. :/
[no name] 13-Aug-16 8:07am    
No, sorry, that has absolut nothing to do with simulating Color mixing of paints. Compare mixing paints Subtractive color - Wikipedia, the free encyclopedia[^] and mixing RGB Color for e.g. a Screen Additive color - Wikipedia, the free encyclopedia[^].
The answer would deserves a 1, I do _not_ vote...
Member 11841791 13-Aug-16 8:13am    
Woah, means of mixing seems to have fancy names. Thanks for clarifying!
Member 11841791 13-Aug-16 8:17am    
Also this is what the .Lerp function does. It basically moves one color to another color with a given value. (0.5f) in your example.
[no name] 13-Aug-16 8:18am    
I didn't make an example :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900