archive: September 2009

07
SEP
2009

As the lyrics to Twinkle Twinkle Littler Star go:

Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky.

This is now true for my flash header. After three days of looking for the perfect star animation and designing the very complex code that will add stars in intervals (or all at once if it has gotten to that point) or to remove the stars in intervals (or all of the stars if it has gotten to that point).

I do have it coded so that if it hasn’t reached the programmed “start hour” for stars to be added it does not add them. It does check every minute (if you are one of those people who are just in awe of my flash header) and will start adding stars if needed. If you come to the site and it’s already passed the “start hour” the code figures out how many stars you would have seen. So currently every 20 minutes (after the “start hour”)  it adds 25 stars to the sky.

function init(event:TimerEvent = null):void {

 // Still needed even though we have the date compare class. This figures out
 // how many stars we need to add.
 var hour=dT.hour==0?24:dT.hour;
 if (hour < startStarHour) { hour+=24 }    // for those 0:00 (12am) to 5:00 (5am) visitors.
 var minute=((hour-startStarHour)*60)+dT.mins;

 intervalStars=defintervalStars*(Math.floor(minute/intervalminute)+1);

 if (intervalStars>maxStars) {
 intervalStars=maxStars;// don't need to send the huge number.. duh!
 }

 if ( (dT.compareTime(startStarHour, 00)) || (dT.compareTime(endStarHour, 00, true)) ) {

 // Stop the timer asap!
 timerInit.stop();

 // Add first group of stars when we start.. but that's it.
 addStars();
 // Animate the first batch ASAP!
 animateStars();

 // Return the interval Stars to the default levels after init.
 intervalStars=defintervalStars;

 // Start the timers.
 timerStar.start();
 timerminute.start();

 }
}

So you are asking yourself what if it was “start hour” plus 19 minutes. Using (Line 5, 6, and 7) we figure out that we should only be doing “1 times” the “default star interval adding”. Now that we have the number of stars we are going to use (Line 9 or 11) lets go ahead and generate the stars and start the animation. The animation goes through each of the stars (Sorry! This code will not be posted!). Now since we don’t want to add potentially more stars at once on the next run of the “addStars” code we force the interval stars back to the default and start the timer needed (Line 29 and 30). timerStar is the timer that runs the animation on the stars. timerMinute is the timer that runs the “addStars” code every x minutes.

In any case if you have any questions be sure to post comments! Even to give me mad props! :)

For those reading this during the day, you will have to change your clocks right now to at least 8pm and no later than 6am to see some stars. Otherwise come back during the night time to check out the stars! :)

Comments 0

Commenting is closed

No Comments Yet