Official website for Web Designer - defining the internet through beautiful design
FOLLOW US ON:
Author: Mark Billen
28th June 2010

Flash time-lapse headers

12 The main function

12 The main function
It looks complex but it isn’t! This is the function which will be controlling all the MCs which have 1 or 0 states, eg different graphics over two frames. In our case it will be the lights. To define the time period, we have to convert hours into minutes, eg 11am = 11*60minutes> 660. Therefore 11-12am is 660–720. Full step code is within the project files.

TimingDemo();
function TimingDemo() {
count++;

var lightPercent:Number;
var nightPercent:Number;
var dayPercent:Number=count/max;

// Sun rotation
if ( (count >= sunrise) && (count <= sunset) ) {
lightPercent = (count-sunrise) / (sunset-sunrise);
Sun.rotation = 325 + (70*lightPercent);
}

// Moon rotation
if ( (count >= moonrise) || (count <= moonset) ) {
mooncount++;
nightPercent = mooncount / (
(max-moonrise)+moonset );
Moon.rotation = 330 + (60*nightPercent);
} else {

13 Brighten it up/down
We want to be adjusting the brightness of all the elements over day/night. We will achieve that using the regular brightness attribute. We can also create darker/brighter for different elements (c,c2 etc), completely black for the ones far away and not so dark for the ones in the middle for example. Full step code is within the project files.

function SunRise(time) {
if ((time > 450) && (time < 630)) {
var percent = (time-450) / 180;
nightSky.alpha = 1-(1*percent);
var c:Color=new Color();
var c2:Color=new Color();
c.brightness = -0.8+(1*(percent*0.8));
c2.brightness=-1+percent;

hills.sign.transform.colorTransform=c2;
hills.transform.colorTransform=c;
grass.transform.colorTransform=c2;
bush.transform.colorTransform=c;
house.building.transform.colorTransform=c2;
bench.transform.colorTransform=c;
lamp.lampPost.transform.colorTransform=c;
houses.house.transform.colorTransform=c;
sale.saleTab.transform.colorTransform=c;
}
}

14 Once per minute switch
Finally, note that we tweaked the timing according to our liking, we can switch the updating of the scene to once per minute so that it lasts the whole day. The only thing we need to do is to change the ‘speed’ variable at the very top to 60,000 (1000s equals one second hence 60 seconds equals 60,000).

var speed:Number=60000

Pages: 1 2 3 4

  • Tell a Friend
  • Follow our Twitter to find out about all the latest web development, news, reviews, previews, interviews, features and a whole more.

    10 Comments »

    Trackbacks

    What's your opinion?

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    * Required fields