here is the CLOCKFACE script...coded in 3 MINUTES...17 LINES of CODE

Eric Chatonet eric.chatonet at sosmartsoftware.com
Wed Jun 8 11:40:01 EDT 2005


Hi Geoff,

Kudos.
Very impressed to see how much a code can be improved again and again.
Just a little thing: with this new very clever code, the clock will  
not be at time just when opening ;-)
So 4 lines more and 2 repetitions that are not satisfying: I bet you  
will find a better solution in 3 minutes!

on openCard
   setTime true
end openCard

on setTime pFlag
   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 pFlag then
     set the angle of grc "Minute" to 90 - (6 * T[2]) - (T[3] div 10)
     set the angle of grc "Hour" to 90 - (30 * T[1]) - (T[2] div 2)
   end if
   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

Best regards from Paris,

Eric Chatonet.

Le 8 juin 05 à 16:04, Geoff Canyon a écrit :

> 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

----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Plugins, tutorials and more on our website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        eric.chatonet at sosmartsoftware.com/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------



More information about the use-livecode mailing list