Yet Another Clock
Geoff Canyon
geoff at runrev.com
Wed Jun 1 03:44:20 EDT 2005
My first thought was that the whole thing could be reduced to
periodic "move to the points of..." task. That doesn't work out very
well. I tried:
move image "sBall" to the points of grc "_ball" in 60 seconds
That gave me a good second hand, but CPU usages was up at 70 percent.
Not good. So I went for minor changes to the existing code.
Below is a modified script. Changes:
-- replaced currH,currM,currS with a local array. This complicates
the repeat a bit because I have to track both 123 and HMS, but one
statement -- put char i of "HMS" into C -- handles that. The upside
is that I don't have to use value or do anywhere.
-- replaced: if N = 0 then put 60 into N
with: put (T[i] + 59) mod 60 + 1 into T[i]
The advantage/necessity is that I'm now adding the minutes
fraction to the hour position. It can now be greater than 60 (any
time from 12:12 to 12:59) The new statement turns 0 into 60, leaves 1
to 60 alone, and turns 61,62,63... into 1,2,3...
-- replaced the set the loc of image command into a move command. The
balls look much nicer scooting along rather than jumping ;-)
-- used split rather than itemDelimiter
I think that's it, maybe there are a few other minor points. The line
count dropped a bit. CPU usage with this script is about 8 percent.
For comparison, the scripts from yesterday that set the startAngle of
a graphic averaged about 1.5 percent.
geoff
on preOpenStack
set loc of this stack to the screenLoc
setTime
end preOpenStack
local sLocation -- array of the locations of the balls
local ringPoints,ringLoc
on setTime
if ringPoints is empty then put the points of grc "_ring" into
ringPoints
if ringLoc is empty then put the loc of grc "_ring" into ringLoc
put word 1 of the long time into T
split T using ":"
repeat with i = 1 to 3
put char i of "HMS" into C
if i = 1 then put T[1] * 5 + T[2] div 12 into T[1] -- hours
works off minutes as well
put (T[i] + 59) mod 60 + 1 into T[i]
if sLocation[i] = T[i] then next repeat
move img (C & "ball") to (line T[i] of ringPoints) without waiting
put T[i] into sLocation[i]
set the points of grc (C & "seg") to (line T[i] of
ringPoints),ringLoc
end repeat
send "setTime" to me in (1 - (the long seconds mod 1)) seconds
end setTime
More information about the use-livecode
mailing list