math question

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

math question

Post #1by Rassilon » 10.09.2004, 20:18

OK Ive been trying to figure this out and Ive made it more difficult than it needs to be...Im trying to scale between two RGB values bepending on the value of say C

RGB1 = [ 0.85 0.62 0.72 ]

RGB2 = [ 0.63 0.44 0.90 ]

Now what I want to do is when scale value C = 255 then we reach RGB1 If its in the middle then we could average RGB1 and RGB2. When C = 0 then we reach RGB2...so how could I do this properly?
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 21 years 3 months

Post #2by ajtribick » 10.09.2004, 20:29

Suppose we have the value of the first colour's red component, call it 'a', and the second colour's red component, call it 'b'.

I think the component of the final colour would then be:

(c*a + (255-c)*b)/255

You then do this for the green component and blue component.

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #3by Rassilon » 10.09.2004, 22:56

chaos syndrome wrote:Suppose we have the value of the first colour's red component, call it 'a', and the second colour's red component, call it 'b'.

I think the component of the final colour would then be:

(c*a + (255-c)*b)/255

You then do this for the green component and blue component.


Thanks that worked a hell of a lot better than this:

int blendRGB( int rgb1, int rgb2, int blend) {
float lo_p = ((255 - (float)blend)+1) / 256;
float hi_p = ((float)blend +1) / 256;
rgb1 *= lo_p;
rgb2 *= hi_p;
return ((rgb1 * rgb2) / 2);
}

I now use this:

#define BLENDRGB(a, b, c) (c*a + (255-c)*b)/255
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!


Return to “Development”