User manual

76
If the second has changed in respect to the last one drawn changed, the graphics of the clock is updated by
the following statement. If nothing has changed, the graphics is not updated, and the loop restarts with yet
another query of the current system time.
pygame.draw.circle(FIELD, WHITE, MP, 182)
A white circular area is drawn first, which covers the hand completely. The radius with 182 pixels is slightly
larger than the longest pointer, to ensure that no remnants remain. It is by far easier to draw an over-all
surface of a circle than to cover the last drawn pointer accurately to the pixel with paint.
pygame.draw.line(FIELD, BLACK, MP, point(120, hm), 6)
This line draws the hour hand as a line with a width of 6 pixels starting from the midpoint, 120 pixels long at
an anglethat is specified by the variable
hm. We have not used so far the function pygame.draw.line(). The
command requires five parameters:
Surface
specifies the drawing canvas, which is FIELD in the example.
Color
specifies the colour of the circle, in the example, the previously defined color BLACK.
Startpoint
indicates the starting point of the line, in this example it is the midpoint of the clock.
Endpoint
indicates the end point of the line, in this example it is the function point() calculated from
the angle of the hour hand.
Thickness
is the line width.
This same function also draws the other two hands of the clock.
pygame.draw.line(FIELD, BLACK, MP, point(170, m), 4)
This line draws the hour hand as a line with a width of 4 pixels starting from the midpoint, 170 pixels long at
an angle that is specified by the minute value.
pygame.draw.line(FIELD, RED, MP, point(180, s), 2)
This line draws the minute hand as a red line with a width of 2 pixels starting from the midpoint, 180 pixels
long at an angle, which is specified by the second value.
s1 = s the second which is now displayed is stored in the variable s1 to compare this value with the current
second in the next loop run.
pygame.display.set_caption(“Current time: " +
time.asctime())
This line writes the current time in digital form into the window caption. The function time.asctime() of
the
time library is used here, which delivers the time as ready formatted string.