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

GPolygon(**keywords)

Constructor: 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. The keywords are the same as the attribute names. 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.

Parameter:keywords – dictionary of keyword arguments

Precondition: See below.

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.

contains(x, y)

Returns: True if this shape contains the point (x,y), False otherwise.

This method cycles through each triangle in the triangle fan and tests each triangle for inclusion.

Parameter:x – x coordinate of point to check

Precondition: an int or float

Parameter:y – y coordinate of point to check

Precondition: an int or float