[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LOGO-L> Clock



There is a change I've been meaning to make to the clock example
for a long time but just did not take the time to do it.
Here it is:

Sidebar: Everyone has their pet peeve. One of my many is programs
that have infinite loops. Here is a slight modification that
uses ONLY the amount of CPU needed and leaves MSWLogo free
to do other things. Example project would be draw 10 clocks with
appropriate times around the world.

Note that the LOOP procedure no longer calls itself and that
the procedure MAIN returns immediately, but the clock keeps
running !!!! This is fundamental in how programmers program
today on modern systems. It's called event driven programming.
What better event to use than an event timer to drive a clock.

Another cool project would be to build a Stop Watch with
Reset, Split, Elapse Time etc. Use the MOUSEON Function to
to "Click" on Areas of the Stop Watch to perform the desired
actions. Or build a watch with an alarm that uses your own
voice to say "Wake up".

to loop
if not equalp :now word last bl item 4 time last item 4 time~
   [erase_hands draw_hands]
end

to main
setsc 0 cs
face
draw_hands
settimer 1 1000 [loop]
end


Yehuka wrote:
> 
> Hi,
> 
> The following program draws a "real" clock. It shows the current time,
> based on the system clock.
> In simpler clocks-programs, the minutes hand is updated once in a
> minute, and the hours hand is updated once in an hour. In this clock,
> all the hands are continuously updating.
> 
> ========================================================
> to main
> setsc 0 cs
> face
> draw_hands
> loop
> end
> 
> to face
> setpc 1 setpensize[4 4] pu
> for[tick 1 12][fd 80 pd fd 10 pu bk 90 rt 30]
> end
> 
> to draw_hands
> setpc 4 setpensize[4 4]         ;                    hours hand
> sph 0 0 hur*30+min/2+sec/120 bk 10 fd 60 make "hur_head heading
>         setpensize[2 2]         ;                  minutes hand
> sph 0 0 min*6+sec/10 bk 10 fd 85 make "min_head heading
> setpc 6 setpensize[1 1]         ;                  seconds hand
> sph 0 0 sec*6 fd 65 make "sec_head heading
> end
> 
> to loop
> if not equalp :now word last bl item 4 time last item 4 time~
>    [erase_hands draw_hands]
> loop
> end
> 
> to erase_hands
> setpc 0 setpensize[4 4]
> sph 0 0 :hur_head bk 10 fd 60  ;                     hours hand
> sph 0 0 :min_head bk 10 fd 85  ;                   minutes hand
> sph 0 0 :sec_head fd 65        ;                   seconds hand
> end
> 
> to hur                         ;    extract the hours from TIME
> op remainder word first item 4 time first bf item 4 time 12
> end
> 
> to min                         ;  extract the minutes from TIME
> op word item 4 item 4 time item 5 item 4 time
> end
> 
> to sec                         ;  extract the seconds from TIME
> make "now word last bl item 4 time last item 4 time
> op word last bl item 4 time last item 4 time
> end
> ========================================================
> 
> SPH is a useful library procedure:
> 
> to sph :x :y :head
> pu setxy :x :y pd
> seth :head
> end
> 
> You might inspect a different clock, written by George, in the
> examples directory that comes with MSWLogo.
> 
> Enjoy it,
> 
> [[Yehuda]]

-- 
===============================================================
George Mills
email: mills@softronix.com
http://www.softronix.com
The www page contains some very powerful educational software.
Our single most important investment is our kids.
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home