A different analog clock

Michael J. Lew michaell at unimelb.edu.au
Tue Feb 5 16:50:01 EST 2002


I made a clock (using Rev) a while ago to encourage my young son to 
read "real" time rather than digital. I made use of standard 
trigonometry and it works nicely. Here are the working bits (without 
needing to sort out a download strategy!).

In a button:

on mouseUp
   global gClockRunning
   if the label of me is "Stop" then
     put false into gClockRunning
     cancel the tickMessageID of group "clock"
     set the label of me to "Start"
   else
     if the optionKey is down then
       --set the clock to computer time
       set the itemDelimiter to ":"
       put item 1 of the long time into theHour
       put item 2 of the long time into theMin
       put word 1 of item 3 of the long time into theSec
       set the clockTime of group "clock" to (theHour*3600 + theMin*60 + theSec)
     end if
     send "runClock" to group "clock"
     set the label of me to "Stop"
   end if
end mouseUp

In the group that has three clock hands and a circle called spindle 
at the centre:

on oneTick
   global gClockRunning
   if gClockRunning then send "oneTick" to me in 500 milliseconds
   set the tickMessageID of me to the result
   --seconds
   put the secondHandLength of group "clock" into L
   put the clockTime of group "clock" + 1 into currentTime
   put the long time into theTime
   convert theTime to dateItems
   put item 6 of theTime into mySec
   add item 5 of theTime*60 to mySec
   add item 4 of theTime*3600 to mySec

   put -pi/2 +mySec*2*pi/60 into theta
   put round(L*sin(theta)) into y
   put round(L*cos(theta)) into x
   put the loc of graphic "spindle" into myPoint
   add x to item 1 of myPoint
   add y to item 2 of myPoint
   put the loc of graphic "spindle"  & return & myPoint into handPoints
   set the points of graphic "secondHand" to handPoints
   --minutes (do only every 6 seconds)
   if currentTime mod 6 = 0 then
     put the minuteHandLength of group "clock" into L
     put -pi/2 +mySec*2*pi/3600 into theta
     put round(L*sin(theta)) into y
     put round(L*cos(theta)) into x
     put the loc of graphic "spindle" into myPoint
     add x to item 1 of myPoint
     add y to item 2 of myPoint
     put the loc of graphic "spindle"  & return & myPoint into handPoints
     set the points of graphic "minuteHand" to handPoints
   end if
   --hours (do only every 60 seconds)
   if currentTime mod 60 = 0 then
     put the hourHandLength of group "clock" into L
     put -pi/2 +mySec*2*pi/(12*60*60) into theta
     put round(L*sin(theta)) into y
     put round(L*cos(theta)) into x
     put the loc of graphic "spindle" into myPoint
     add x to item 1 of myPoint
     add y to item 2 of myPoint
     put the loc of graphic "spindle"  & return & myPoint into handPoints
     set the points of graphic "hourHand" to handPoints
   end if
end oneTick

on runClock
   global gClockRunning
   put true into gClockRunning
   oneTick
end runClock

Regards,
-- 
Michael J. Lew

Senior Lecturer
Department of Pharmacology
The University of Melbourne
Parkville 3010
Victoria
Australia

Phone +613 8344 8304

**
New email address: michaell at unimelb.edu.au
**



More information about the metacard mailing list