Tags

Related Posts

Share This

Generalized equation for displaying daylight

this is ages old now, but i’ve still never used it on a live site..

//this is the code for night, which accounts for midnight and
//a gap during the day.
onClipEvent (enterFrame) {
var totalmins;
var opac = 0;
var pcnt = 0;
//declare a few constants here to save the searching later.
//these are set as minutes.
dayin = 200;
mypeak = 720;//midnight in minutes
dayout = 1320;
//announced vars and constants, about to ask for time from system.
time = new Date ();
totalmins = (60 * time.getHours()) + time.getMinutes();
//time to setup some alphas based on times of day.
//the first checks to see if it is morning.
if ((totalmins >= dayin) && (totalmins <= mypeak)){
pcnt = (((totalmins – dayin)/(mypeak – dayin)) * 100);
//this second checks to see if it is early morning.
} else if ((totalmins >= mypeak) && (totalmins <= dayout)){
pcnt = (100 – ((totalmins – mypeak)/(dayout – mypeak)) * 100);
//if it it neither…
} else pcnt = 0;

//now we send this variable percentage in to be rounded
//and applied to the MC’s properties.
opac = math.round (pcnt);
this._alpha = opac;
}