I came up with a radically different approach. Several iterations
ago, we realized that we didn't have to guess when it would be time
to set the clock graphics. We could use 1-(the long seconds mod 1) to
get a message sent exactly when we need it.
Well, we're still guessing at when it's time to move the minute hand
or the hour hand, and we don't need to. The minute hand moves one
degree every ten seconds, the hour hand one degree every two minutes.
The tests to determine this are simple. The natural thing to do is
set the second hand, check to see if the minute hand needs to be set,
and if it does check to see if the hour hand needs to be set. At each
step, I want to exit if appropriate. The stumbling block was the
send...in. I need to get to the end to do it.
Then I realized -- the send...in doesn't have to be the last step. It
can come at any point. So here's the script now:
on openCard
setTime
end openCard
on setTime
send "setTime" to me in 1 - (the long seconds mod 1) seconds
put word 1 of the long time into T --8:13:15
put T & char 2 to 7 of (the long seconds mod 1) into fld "Time"
split T using ":"
set the angle of grc "Second" to 450 - (6 * T[3])
if T[3] mod 10 <> 0 then exit setTime
set the angle of grc "Minute" to 90 - (6 * T[2]) - (T[3] div 10)
if T[3] <> 0 or T[2] mod 2 <> 0 then exit setTime
set the angle of grc "Hour" to 90 - (30 * T[1]) - (T[2] div 2)
end setTime
Notice how simple the check is for the minute hand. Nine out of ten
seconds, the only thing this routine is going to do other than set
the second hand is check whether T[3] mod 10 is 0. This also saves
some time and math because I don't have to check the angle of the
graphics anymore. I just need to set it when the time is right. So no
more mod 360.
This is the same number of lines, but shorter and cleaner, I think. I
could save two lines by adding an else to the if statements:
if t[3] mod 10 <> 0 then exit setTime else set the angle of grc
"Minute" to 90 - (6 * T[2]) - (T[3] div 10)
But that seems artificial and less clear than using two lines.
Let me know what you think.
regards,
Geoff
On Jun 7, 2005, at 9:01 AM, Dennis Brown wrote:
Dar pointed out that this clock does not have a graceful stop. I
changed the clock in my user space (see3d) to shut down the clock
when the card is closed.
Dennis
On Jun 7, 2005, at 12:40 AM, Geoff Canyon wrote:
I've posted the new revision:
on openCard
setTime
end openCard
on setTime
put word 1 of the long time into T --8:13:15
put T & char 2 to 5 of (the long seconds mod 1) into fld "Time"
split T using ":"
get (450 - (30 * T[1]) - (T[2] div 2)) mod 360
if (the angle of grc "Hour") <> it then set the angle of grc
"Hour" to it
get (450 - (6 * T[2]) - (T[3] div 10)) mod 360
if (the angle of grc "Minute") <> it then set the angle of grc
"Minute" to it
set the angle of grc "Second" to 450 - (6 * T[3])
send "setTime" to me in 1 - (the long seconds mod 1) seconds
end setTime
On Jun 6, 2005, at 9:38 AM, Dennis Brown wrote:
Good catch.
As was pointed out before, trunc(T[2] / 2) can be simplified to (T
[2] div 2)
_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution