Polygon

Polygon objects are created using the following functions.  Polygons are drawn by specifying their corners using two parallel lists of x and y coordinates.

Function Description
Polygon(xPoints, yPoints) Creates a Polygon with corners specified by the xPoints and yPoints lists.  The two lists are parallel, i.e., the first items correspond to the first polygon corner (x1, y1), the next items to the second corner (x2, y2), and so on.
Polygon(xPoints, yPoints, color, filled, thickness) Creates a Polygon with corners specified by the xPoints and yPoints lists,  color (e.g. Color.BLACK (default), Color.ORANGE or Color(255, 0, 255), using specific RGB values), filled (boolean – default is False), and thickness (default is 1 pixel).

Once a Polygon has been created, it may be added to a Display.

poly1 = Polygon([312, 366, 510, 443], [244, 210, 312, 346])
d.add(poly1)

Finally, you may use the following functions:

Function Description
poly1.setColor(color) Changes color to the specified color (e.g. Color.BLACK or Color(255, 0, 255), using specific RGB values).  If the color parameter is omitted, a color selection dialog box will be presented.
poly1.getColor() Returns the current color.
poly1.getX() Returns the x coordinate (in pixels).
poly1.getY() Returns the y coordinate (in pixels).
poly1.setX(x) Sets the x coordinate (in pixels).
poly1.setY(y) Sets the y coordinate (in pixels).
poly1.encloses(other) Returns True if poly1 encloses other graphics object.
poly1.intersects(other) Returns True if poly1 intersects other graphics object.
poly1.getPosition() Returns the position as an (x, y) tuple.  This is the top-left corner of the box that encloses the polygon.
poly1.setPosition(x, y) Sets the position to x, y.  This is the top-left corner of the box that encloses the polygon.