0

I want to mix colors like you would with paint or light.

Does anyone know of some efficient formulas or tools to get the job done? It should be simple but so far it's not.

For instance, if you mix yellow and blue, you should green

However, you get gray!!!

The problem is that css uses RGB which I find truly baffling. For some reason, "yellow" is represented by green and red. That is to say: rgb(255,255,0)="yellow"!

I'm sure there's some reason behind all this, but the math is now funky.

Let's say you use JavaScript to mix yellow and blue to get green. You get:

var green = rgb( 
  Math.round( ( 255 + 0 ) / 2 = **128** ),
  Math.round( ( 255 + 0 ) / 2 = **128** ),
  Matn.round( ( 0 + 255 ) / 2 = **128** )
  )
= rgb(128,128,128)

That's gray.

Any insights into this conundrum would make me a very satisfied coder and might even help me make a cool app.

TY in advance.

Methodician
  • 2,396
  • 5
  • 30
  • 49
  • 1
    See https://en.wikipedia.org/wiki/RGB_color_model and https://en.wikipedia.org/wiki/Color_theory – Gabriele Petrioli Oct 16 '16 at 23:20
  • There is no *"Y"* in *"RGB"* – charlietfl Oct 16 '16 at 23:21
  • Sure there is. It's 255,255,0. I mean you can see yellow on the screen so what are you saying? Please be helpful if you can. – Methodician Oct 16 '16 at 23:26
  • 2
    The answer hinges on the theory of color perception and the difference between additive (RGB) and subtractive (CMYK) color. A full explanation is out of scope for StackOverflow and this question is too broad. Your intuition about color is based on the subtractive model, which does not apply to RGB. Read the links provided by @GabyakaG.Petrioli – Jim Garrison Oct 16 '16 at 23:29
  • It appears that this challenge is far, far more complex than I had anticipated. No wonder my usual hack-google-hack approach didn't yield a solution! – Methodician Oct 17 '16 at 00:58

0 Answers0