Class GTriangle¶
This class represents a solid triangle to draw on the screen. The triangle is defined as a sequence of three points. Just as with the GPath class (which is the parent of this class), it has an attribute points which represents these points as an even-length sequence of ints or floats.
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.
As with GPath, the attributes x and y may be used to shift the triangle position. By default, these values are 0. However, if they are nonzero, then Python will add them to the triangle vertices. Similarly, the attributes width and height are immutable, and are computed directly from the points
Constructor¶
-
GTriangle
(**keywords)¶ Constructor: Creates a new solid triangle.
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 red triangle with vertices (0,0), (2,3), and (0,4), use the constructor call
GTriangle(points=[0,0,2,3,0,4],fillcolor=colormodel.RED)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.
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 uses a standard test for triangle 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