pygame documentation |
|| Pygame Home || Help Contents || Reference Index || camera || cdrom || Color || cursors || display || draw || event || examples || font || gfxdraw || image || joystick || key || locals || mask || math || midi || mixer || mouse || movie || music || Overlay || PixelArray || pixelcopy || pygame || Rect || scrap || sndarray || sprite || Surface || surfarray || tests || time || transform || version |
pygame.draw.rect | — | draw a rectangle shape |
pygame.draw.polygon | — | draw a shape with any number of sides |
pygame.draw.circle | — | draw a circle around a point |
pygame.draw.ellipse | — | draw a round shape inside a rectangle |
pygame.draw.arc | — | draw a partial section of an ellipse |
pygame.draw.line | — | draw a straight line segment |
pygame.draw.lines | — | draw multiple contiguous line segments |
pygame.draw.aaline | — | draw fine antialiased lines |
pygame.draw.aalines | — | draw a connected sequence of antialiased lines |
Draw several simple shapes to a Surface. These functions will work for rendering to any format of Surface. Rendering to hardware Surfaces will be slower than regular software Surfaces.
Most of the functions take a width argument to represent the size of stroke around the edge of the shape. If a width of 0 is passed the function will actually solid fill the entire shape.
All the drawing functions respect the clip area for the Surface, and will be constrained to that area. The functions return a rectangle representing the bounding area of changed pixels.
Most of the arguments accept a color argument that is an RGB triplet. These can also accept an RGBA quadruplet. The alpha value will be written directly into the Surface if it contains pixel alphas, but the draw function will not draw transparently. The color argument can also be an integer pixel value that is already mapped to the Surface’s pixel format.
These functions must temporarily lock the Surface they are operating on. Many sequential drawing calls can be sped up by locking and unlocking the Surface object around the draw calls.
Draws a rectangular shape on the Surface. The given Rect is the area of the rectangle. The width argument is the thickness to draw the outer edge. If width is zero then the rectangle will be filled.
Keep in mind the Surface.fill() method works just as well for drawing filled rectangles. In fact the Surface.fill() can be hardware accelerated on some platforms with both software and hardware display modes.
Draws a polygonal shape on the Surface. The pointlist argument is the vertices of the polygon. The width argument is the thickness to draw the outer edge. If width is zero then the polygon will be filled.
For aapolygon, use aalines with the ‘closed’ parameter.
Draws a circular shape on the Surface. The pos argument is the center of the circle, and radius is the size. The width argument is the thickness to draw the outer edge. If width is zero then the circle will be filled.
Draws an elliptical shape on the Surface. The given rectangle is the area that the circle will fill. The width argument is the thickness to draw the outer edge. If width is zero then the ellipse will be filled.
Draws an elliptical arc on the Surface. The rect argument is the area that the ellipse will fill. The two angle arguments are the initial and final angle in radians, with the zero on the right. The width argument is the thickness to draw the outer edge.
Draw a straight line segment on a Surface. There are no endcaps, the ends are squared off for thick lines.
Draw a sequence of lines on a Surface. The pointlist argument is a series of points that are connected by a line. If the closed argument is true an additional line segment is drawn between the first and last points.
This does not draw any endcaps or miter joints. Lines with sharp corners and wide line widths can have improper looking corners.
Draws an anti-aliased line on a surface. This will respect the clipping rectangle. A bounding box of the affected area is returned returned as a rectangle. If blend is true, the shades will be be blended with existing pixel shades instead of overwriting them. This function accepts floating point values for the end points.
Draws a sequence on a surface. You must pass at least two points in the sequence of points. The closed argument is a simple boolean and if true, a line will be draw between the first and last points. The boolean blend argument set to true will blend the shades with existing shades instead of overwriting them. This function accepts floating point values for the end points.