mixing colors

For general discussion related FlowStone
Post Reply
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

mixing colors

Post by tester »

Changing the topic a little bit.

How to mix multiple colors in "light" way and "paint" way?

Let say that I have an array of RGB values (0-255 ranges; this comes out of a module):

rrr/ggg/bbb
rrr/ggg/bbb
rrr/ggg/bbb
...

And as the output reslut - I'd like to have one color as if I was mixing lights, and second color as if I was mixing paints.

From what I see - one formula is probably just to sum on all rrr/ggg/bbb channels and divide by amount of elements in the array (subtractive/paint type?). But I don't know how to approach the second one. Especially because many colors in FS are just idealistic with 0 or 255 thresholds.

Trog - I don't seek for ultra-hyper-realistic sRGB, just something brief. ;-)
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
TheOm
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: mixing colors

Post by TheOm »

I would first convert the colours from RGB to HSV and then take the average values.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: mixing colors

Post by tester »

Okay, thanks. Tested, and while results are not quite as expected (thus - I will keep probably only one mixing model), this conversion RGB-HSV will be useful for other thing.

BTW, @TheOm, you sound very familiar. :mrgreen:
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: mixing colors

Post by trogluddite »

For 'light mix', summing R, G, B would be a reasonable approximation - the hue would be about right, but as you say the limited (0-255) would affect the brightness, so the values will need scaling to keep in range.

For paints, the colour depends on the light that the pigments absorb, and your eye sees the remainder that bounces off - mixing two pigments combines their 'negative' spectrum. (mixing pigments always makes the color darker - hence all oil painters always have a huge tube of white paint!).

So this 'inversion' might be worth a go...

Take (255 -R), (255 - G), (255 - B) for each colour.
Take averages.
Take (255 -R), (255 - G), (255 - B) of result.

Not tried that, it might distort the hue because the traditional painter's primary colours are Red, Blue, Yellow - not Cyan, Yellow, Magenta (opposites of R, G, B).

Mixing in the HSV color space would give other results, though. For example yellow and blue are 'complementary' colours - if you mix those ('light' method), you would get white/grey (zero saturation). But an HSV average will still give you a very saturated color of a different hue.
It is a good way to create a 'spectrum' of hues, so the results will often have more 'visual appeal', but unlikely to give results like mixing lights or pigments.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Post Reply