Monday, 26 September 2011

TODAY WE MADE CLOCKS.



A rough explanation:


Made a timer that ticks every 1000 milliseconds (1 second).



var timer:Timer=new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, thingy);
timer.start();


function thingy(event:TimerEvent)
{



Made variables to obtain the hour, minute and second from the system clock.


var time = new Date();
var hourthing = time.getHours();
var minutething = time.getMinutes();
var secondthing = time.getSeconds();


So by this point, flash knows the hour, minute and second, and checks these values every second. Next up I made an analogue clock, by making a (rather beautiful) clock face and three hands, placing the hands on the face and naming their instances myhourhand, myminutehand and my secondhand, which rotate at different speeds to .. well, tell the time:

myhourhand.rotation = 30 * hourthing + minutething / 2;
myminutehand.rotation = 6 * minutething;
mysecondhand.rotation = 6 * secondthing;




Next was digital, which was just a case of creating text fields and applying the digital values to them. If the value was less than 10, I asked it to add "0" to the front, to keep the value 2 digits...

if (hourthing <10){
texthour.text = "0" + hourthing +":";
}
else{texthour.text = hourthing + ":"; 
}

that does hours, made similar for minutes and seconds...





there was also a bar clock (think a graph for the time) based on the window being 400 pixels high:


hourbar.height = (400 / 24) * hourthing;
minutebar.height = 400 / 60 * minutething;
secondbar.height = 400 / 60 * secondthing;





and finally a digital clock with a photo representing each number from 0 - 9, à la http://www.exquisiteclock.org/clock/index.php?live=1&tag=random. Some poor guy got roped into posing for the photographs, and the result was rough, but it worked. There was a tricky bit of actionscript needed to find the value of the digit for the 'tens' and 'ones' columns of the time values (EG; the "2" and "6" from the value "26"), which is here:


second1.gotoAndStop(Math.floor(secondthing/10)+1);
second2.gotoAndStop(secondthing - (Math.floor((secondthing/10))*10)+1);



So there it is, some clocks what I made. This is only a very basic visual representation of some of the things that can be done with the functions associated with time. Hopefully will have some mint stuff up over the next few weeks. Peace. :)

No comments:

Post a Comment