views:

560

answers:

3

Hey all,

I want to change the color Bright Green to Dark Red over time (240 hours). The best way I can see is to change the hex combo from 00FF00 to FF0000.

I don't know how to dynamically count up to FF0000 from 00FF00 for the life of me. I'm looking over a 10 day period, so most likely over 240 hours to increment.

Can anyone help me out?

I never took an algorithms class so I think that might have something to do with this problem.

If you have a better way to do this, then let me know.

I am looking for some kind of code here. Thanks guys. It can be in any language but will inevitably be converted to C#.

+7  A: 

Just think about it in terms of the components. Even though it looks like one big hex number, it's actually three side-by-side.

At the start, red is 0, green is 255 (FF), blue is 0.
At the end, red is 255, green is 0, blue is 0.

So, every (amount of time you have / 255), increment red by 1 and decrement green by 1.

Chad Birch
Your both correct, which sucks. Would like to give the answer to both you guys.
Scott
Well, Scott made a good choice, because Chad Birch's is much easier than Pete Kirkham's answer.
David Grayson
+3  A: 

time_remaining (value varies from 0 to 239)

green = 255 * (time_remaining / 239)
red = 255 - green
blue = 0

color = (red, green, blue)

Jim H.
Your both correct, which sucks. Would like to give the answer to both you guys.
Scott
+18  A: 
Pete Kirkham
an example on how to do this would be nice though =)
Svish
Cool answer! The wikipedia article even has the conversion maths between rgb and hsv so an implementation in c# should be possible, 'cos I think there is no direct support for colours expressed in HSV...?
flq
+1 for teaching me something new
Nifle