Yet Another Clock

Levi Kendall ljk144 at gmail.com
Wed Jun 1 09:06:06 EDT 2005


I also wanted something similar to this, so I allowed all the balls to
assume their positions at any point in between the points that were
previously being used.  This is probably the least efficient of any of
the scripts that have been posted but is also probably the "smoothest"
in terms of the display.  It also uses tick 5 so there are several
updates every second rather than the 1 update per second method.

I was also thinking there could be a better way to initialize the
constants since it will be unhappy if applied while it's executing,
but I have not come up with a good alternative yet.



local sCenterX, sCenterY -- used to store the center point of the clock circle
local sRad -- radius of the clock circle
local sAdjust -- used to subtract 90 degrees (in radians) for proper
clock display
local sFullCircle -- radians in a complete circle

on preOpenStack
  set loc of this stack to the screenLoc -- place window in center of screen
  
  put the left of img "ringbase" + (the width of img "ringbase") / 2.0
into sCenterX
  put the top of img "ringbase" + (the height of img "ringbase") / 2.0
into sCenterY
  put (0.5 * pi) into sAdjust -- constant to realign angles for a clock face
  put 100 into sRad -- radius of the clock circle
  put 2.0 * pi into sFullCircle -- radians in a complete circle
  
  setTime
end preOpenStack

on setTime  
  put word 1 of the long time into T
  split T using ":"
  
  put ((T[3] + (the milliseconds mod 1000.0) / 1000.0) / 60.0) into tSecPercent
  put (T[2] / 60.0) + (tSecPercent / 60.0) into tMinPercent
  put (T[1] / 12.0) + (tMinPercent / 12.0) into tHourPercent
  
  put tHourPercent * sFullCircle - sAdjust into tHourTrig
  put tMinPercent * sFullCircle - sAdjust into tMinTrig
  put tSecPercent * sFullCircle - sAdjust into tSecTrig
  
  set loc of img "Hball" to sCenterX + sRad * cos(tHourTrig), sCenterY
+ sRad * sin(tHourTrig)
  set loc of img "Mball" to sCenterX + sRad * cos(tMinTrig), sCenterY
+ sRad * sin(tMinTrig)
  set loc of img "Sball" to sCenterX + sRad * cos(tSecTrig), sCenterY
+ sRad * sin(tSecTrig)
  
  send "setTime" to me in 5 tick
end setTime


More information about the use-livecode mailing list