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]]
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