Class GPolygon

This class represents a solid polygon to draw on the screen. The polygon is a triangle fan from the center of the polyon to the vertices in the attribute points. The center of the polygon is always the point (0,0), unless you reassign the attributes x and y. However, as with GPath, if you assign the attributes x and y, then Python will shift all of the vertices by that same amount. Hence the polygon vertices must be defined as triangle fan centered at the origin.

The interior (fill) color of this triangle is fillcolor, while linecolor is the color of the border. If linewidth is set to 0, then the border is not visible.

The polygon may also be textured by specifying a source image. The texture coordinates of each vertex will be relative to the size of the image. For example, if the image is 64x64, then the quad polygon (-32,-32,-32,32,32,32,32,-32) will be a rectangle equal to the image. You can adjust the size of the source image with the attributes source_width and source_height. If the polygon is larger than the image, then the texture will repeat.

As with GPath, the attributes width and height are immutable, and are computed directly from the points.

Constructor

class game2d.GPolygon(**keywords)

Creates a new solid polyon

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. For example, to create a hexagon, use the constructor call:

GPolygon(points=[87,50,0,100,-87,50,-87,-50,0,-100,87,-50])

As with GPath the width and height attributes of this class are both immutable. They are computed from the list of points.

Parameters

keywords (keys are attribute names) – dictionary of keyword arguments

Attributes

This class does not have any attributes beyond those defined in GPath.

Methods

This class has all of the methods of GPath. In addition, it has the following altered method.

GPolygon.contains(point)

Checks whether this shape contains the point

By default, this method just checks the bounding box of the shape.

Warning: Using this method on a rotated object may slow down your framerate.

Parameters

point (Point2` or a pair of numbers) – the point to check

Returns

True if the shape contains this point

Return type

bool

Return to top level