User manual

75
succession at an angular distance of five minute units; that is achieved by multiplying the angle data by
5
which is passed on to the function.
mainloop = True; s1 = 0 Before the main loop of the program starts, two auxiliary variables are defined,
which are needed in the following process. As in the last program sample,
mainloop indicates whether the
loop should continue running or if the user wants to exit the programme.
s1 saves the last second that was
displayed.
while mainloop:
time = time.localtime()
Now he main loop of the program starts, which in each run, regardless of how long it lasts, writes the actual
time to the object
time. The function time.localtime() of the time library is used for this purpose. The
result is a data structure that is composed of several individual values.
s = time.tm_sec; m = time.tm_min; h = time.tm_hour
The three values, seconds, minutes and hours relevant for the clock are adopted from the structure and
written in three variables
s, m and h.
if h > 12:
h = h – 12
Analogue clocks display only twelve hours. The function time.localtime() provides all time specifications
in 24-hour format. For past midday times
12 hours are simply subtracted.
Time representation for analogue clocks
Depending on the mechanism used, two different displays for analogue clocks are available. In real
analogue running clocks the minute hand performs a uniform circular motion; digitally controlled clocks
such as station clocks, the minute jumps from full minute to the next full minute. The latter method has
the advantage that the time is read accurately read by the minute easily at a glance. Fractions of minutes
are usually not important in everyday life. We also use for our clock application the same method.
However, the hour hand must perform a uniform circular motion. It would be very odd and confusing, if
the hour hand would jump an hour forward at every hour.
hm = (h + m / 60.0) * 5 The variable hm stores the angle of the hour hand in minute units, as applied
throughout the programme. Therefore the minutes value is added to the current hour 1/60. Each minute, the
hour hand advances 1/60 of an hour. The calculated value is multiplied by
5, because the hour hand
advances on the dial five minute units in one hour.
if s1 <> s: The duration of an iteration in the programme is unknown. This means for the analogue clock,
that the graphic does not need to update at each loop run; it needs to update however, if the current second
is different from the last one drawn. Thus the drawn second will be stored in the variable
s1 later on in the
programme; the current second is always expressed in the variable
s.