Drawing Graphics Primitives
This section shows you how to draw circles, rectangles, lines andpoints – that is, all kinds of graphics primitives. A common way to
perform drawing and showing graphics on the screen is that you first create
a graphics.Image object, manipulate that object and then draw it
on the canvas (screen) in the redraw callback function.
This process is called double buffering. The name refers to the fact that
instead of drawing primitives directly on the canvas, which is possible as
well, you draw them in a separate image (buffer) first. This way you do
not have to draw everything again when the canvas must be redrawn, for
example after a popup dialog has cleared a part of the canvas. Instead,
you simply copy the image to the canvas. The Image.blit() function
that handles the copying is typically accelerated by hardware and is, thus,
fast.
To do this, we need to import the graphics module, which gives
access to functions for drawing graphics primitives and loading, saving,
resizing and transforming images. It is loosely based on the Python
Imaging Library (PIL), though it supports only a restricted set of its
functions.
Let’s have a look at the graphics module. Example 31 draws a red
point, a yellow rectangle and some white text to the screen, as shown in
Figure 5.4. We use keyboard keys to draw one of these graphics primitives
on the screen or to draw all primitives at the same time.

No comments:
Post a Comment