I have a beginning colour and I have an ending colour... how do I get the colour now?

Started by
5 comments, last by Syranide 18 years, 9 months ago
My particle system is really starting to look cool, but I need to add the ability to morph between colours. Like my fire might start off as a really bright yellow and then fade into a darker red (as it invariably leaves the middle), but I dunno how to do that. Let's say my start colour is 255, 255, 32 and I want to go to 196, 96, 16 and I know this operation is going to take 3 seconds. What equation can I use? Please don't throw too much math jargon at me, I'm not a very good math student.
"Where genius ends, madness begins."Estauns
Advertisement
difference in r: 255 - 196 = 059
difference in g: 255 - 096 = 159
difference in b: 032 - 016 = 016

difference PER SECOND r: 059 / 3
difference PER SECOND g: 159 / 3
difference PER SECOND b: 016 / 3

difference PER MILLISECOND r: 059 / 3000
difference PER MILLISECOND g: 159 / 3000
difference PER MILLISECOND b: 016 / 3000

You would use the elapsed frame-time to calculate how much difference (delta or step) you have to add to the 'now'-rgb.
Pipo DeClown's solution is the simple way to do it, but you have to be careful because it will also affect the brightness and saturation of the color. For example, going from bright yellow (255, 255, 0) to bright blue (0, 0, 255) will go through medium gray (128, 128, 128) and that might be a problem.

If this is going to be a problem, then you need to convert from RGB to HSV (hue-saturation-value), do the interpolation, and convert back.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Heck, even I didn't think of that, and I use the same basic linear interpolation for colour values. Thanks, JB.
Quote:Original post by JohnBolton
If this is going to be a problem, then you need to convert from RGB to HSV (hue-saturation-value), do the interpolation, and convert back.


Wouldn't that instead make e.g. blending from red to cyan, making it change color from red->purple->blue->cyan (or the other way around the hue).

Which in my eyes would be worse, but of course, it all depends on the situation perhaps.

EDIT: Lab, could that be something which would make nice fadings? I guess that would make it span through a few colors as well, anyone ever tried? (Playing some with photoshop it actually seems to produce sane results, however, there is of course some blending with other colors, but I don't know could be something)


To my mind, interpolating through the colour cube as described is the most logical thing to do. If you want it to look different you just add more points to interpolate between.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Quote:Original post by RAZORUNREAL
To my mind, interpolating through the colour cube as described is the most logical thing to do. If you want it to look different you just add more points to interpolate between.


Am I sleepy, or isn't that the same thing as just interpolating normal RGB-values? (or perhaps that is what it means)


This topic is closed to new replies.

Advertisement