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

Dennis Brown see3d at writeme.com
Mon Jun 6 12:38:47 EDT 2005


Geoff,

Good catch.
As was pointed out before, trunc(T[2] / 2) can be simplified to (T[2]  
div 2)

Dennis

On Jun 6, 2005, at 11:45 AM, Geoff Canyon wrote:

> I've put up a summary of the refinement of this code at:
>
> http://www.inspiredlogic.com/beautiful/clockface.html
>
> I had to make a modification to the below "final" version, both to  
> use the split command and because I realized that sometimes
>
>   450 - (30 * T[1]) - trunc(T[2] / 2)
>
> won't fall into the range 0-359. If it doesn't the value returned  
> by the angle of the graphic the next time won't match (because it  
> is always in 0-359) and so the hour hand's position will be set  
> every second, which we're trying to avoid.
>
> The posted version is now:
>
> 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]) - trunc(T[2] / 2)) mod 360
>   if (the angle of grc "Hour") <> it then set the angle of grc  
> "Hour" to it
>   get (450 - (6 * T[2]) - trunc(T[3] / 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 360+90-(6 * item 3 of T)
>   send "setTime" to me in 1-(the long seconds mod 1) seconds
> end setTime
>
> Let me know if you see an issue with that.
>
> gc
>
>
> On May 30, 2005, at 4:37 PM, Dennis Brown wrote:
>
>
>> That is a good point.  I tested it out, and the useless "set  
>> angle" results in about 70ms of wasted time every second (7%  
>> CPU).  I am surprised it is so high.  Doing the test and skipping  
>> it is a thousand times faster.  I fixed up the script as my own  
>> exercise for the student.  You can see the time lag slightly when  
>> the computer is busy with something else, like loading a web page.
>>
>> Note: the angle calculations had to be changed to match what the  
>> angle returned for these graphics.  The clock is in  my user space  
>> (see3d).  It takes a licking, but keeps on ticking...
>>
>> on openCard
>>   setTime
>> end openCard
>>
>> on setTime
>>   set the itemDelimiter to ":"
>>   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"
>>   get 360+90-(30 * item 1 of T) - trunc((item 2 of T) / 2)
>>   if (the angle of grc "Hour") <> it then set the angle of grc  
>> "Hour" to it
>>   get 360+90-(6 * item 2 of T) - trunc((item 3 of T) / 10)
>>   if (the angle of grc "Minute") <> it then set the angle of grc  
>> "Minute" to it
>>   set the angle of grc "Second" to 360+90-(6 * item 3 of T)
>>   send "setTime" to me in 1-(the long seconds mod 1) seconds
>> end setTime
>>
>>
>> Dennis
>>
>> On May 30, 2005, at 2:21 PM, Geoff Canyon wrote:
>>
>>
>>
>>> On May 30, 2005, at 10:04 AM, Dennis Brown wrote:
>>>
>>>
>>>
>>>
>>>> Nice!  I learn something every minute on this list --four heads  
>>>> are better than one.  I do believe that the clock is down to its  
>>>> essence now.  Every line does something essential, except  
>>>> displaying the "Time" field to check its accuracy.  I put the  
>>>> latest version in my user space also (see3d).
>>>>
>>>>
>>>>
>>>
>>> re: down to its essence -- obviously for this demo it doesn't  
>>> matter, but in practice, I would want to put in code to only  
>>> change the minute and hour hands when they actually need it,  
>>> rather than setting them to the same startAngle (except when they  
>>> actually move) each second. I haven't timed this to see whether  
>>> it's actually a concern.
>>>
>>> And multiple heads are definitely better than one. That's why I  
>>> plan to grow additional heads as soon as possible. ;-)
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>
>>>
>>>
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list