The problem: I want to mix two colors in javascript, and get the result color.
There are a lot of similar question on SO, however I doesn't find anything that actually works correctly. I know that mixing two different colored paints(pigments) and lights will give very different results (http://en.wikipedia.org/wiki/Color_mixing).
Here are the questions and suggested solutions I've already seen, and tried to implement:
1: Mixing two RGB color vectors to get resultant
So, mixing colors in RGB. I implemented it, and in some cases it works in some cases it doesn't.
Working example: Mixing red
with yellow
-> orange
. Great!
http://jsbin.com/afomim/1/edit
Not working example: Mixing blue
with yellow
-> gray
. Not so great! :)
http://jsbin.com/afomim/5/edit
I know that in RGB mixing blue
with yellow
will never make green
, and I understand why.
We will not find the answer here, let's go forward.
2: Adding Colours (Colors) Together like Paint (Blue + Yellow = Green, etc)
Let's try to work with CMYK values as suggested in this discussion. Mixing cyan
with yellow
gives green
:
http://jsbin.com/igaveg/1/edit
but mixing blue
with yellow
results in black
.
http://jsbin.com/igaveg/2/edit -> Not working!
3: How to mix colors "naturally" with C#?
A very similar question. The most upvoted answer suggests to convert colors to LAB, and this solution seems promising.
So I converted my colors to LAB. The conversion algo is correct, I tested it!
http://jsbin.com/oxefox/1/edit
Now I have the two colors in LAB, but how to mix them?
NOTE I know that probably I will not find an algo that mixes blue
with yellow
and will give the perfect green
, but I hope I can generate something similar to green :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…