I'm making a Flash game (ActionScript 3) and for dynamics I'd like to make the background change colour depending on the clients' time of day.

I have a rough idea on how I want to do this,

At sunrise, I want the background to be yellow-orange In the middle of the day, I want the background to be cyan/clear sky colour At sunset, a reddish-orange During the night, a navy blue.

I will be using this method to change the colour of the symbol, which is at default a dark grey colour. (unless someone points out a better way to do this). This means I have access to the red, blue and green components of the background.

On implementing the system itself; I suppose I could simply get the client time and do

if (hour > 9) and (hour < 18)
    colour = SKY_BLUE

and similar for the other times of day, but I'd like it to tween slowly between colours as time progresses. For example, if 6AM is yellow-orange and 9AM is blue, 7:30AM would be yellow moving towards blue. I have a feeling I need to come up with an algorithm to link time to the RGB components of the colour, but I've always been terrible at maths and I can't think of how to do this, so that's why I'm asking.

Please tell me how I would do this, both concept outlining and sample code, or even just tips are welcome. :)

  • 2
    \$\begingroup\$ Look up linear interpolation. \$\endgroup\$
    – House
    Mar 14, 2013 at 20:51

1 Answer 1


Reference Link for Date Time Functions http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html

Using the getHours() & getMinutes function you can decide the change in the color.

The Color Transform code which you have mentioned is pretty good to carry the color operation.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .