Yet Another Clock

Scott Rossi scott at tactilemedia.com
Wed Jun 1 09:52:13 EDT 2005


Recently, Levi Kendall  wrote:

> 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.

Hi Levi:

Nice math-based version you've written there.  Here's a modified version of
your script that will auto-reinitialize itself as needed (there's no penalty
for repeatedly placing values into variables, but reading physical
properties of non-changing objects, ie location, is better done one time).


on preOpenStack
  set loc of this stack to the screenLoc -- place window in center of screen
  setTime
end preOpenStack

local sCenterX, sCenterY -- used to store the center point of the clock
circle
on setTime
  if sCenterX = "" or sCenterY = "" then
    put item 1 of loc of img "ringbase" into sCenterX
    put item 2 of loc of img "ringbase" into sCenterY
  end if
  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
  
  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 item 1 of 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



Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design
-----
E: scott at tactilemedia.com
W: http://www.tactilemedia.com



More information about the use-livecode mailing list