Sign in to follow this  
Estauns

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

Recommended Posts

Estauns    103
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.

Share this post


Link to post
Share on other sites
Pipo DeClown    804
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.

Share this post


Link to post
Share on other sites
JohnBolton    1372
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.

Share this post


Link to post
Share on other sites
sordid    246
Heck, even I didn't think of that, and I use the same basic linear interpolation for colour values. Thanks, JB.

Share this post


Link to post
Share on other sites
Syranide    375
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)

Share this post


Link to post
Share on other sites
RAZORUNREAL    567
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.

Share this post


Link to post
Share on other sites
Syranide    375
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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this