Drawing polygons

Polygons are drawn using the fillPolygon:points:shape:mode: method. The polygon is automatically closed whether or not the first and last points match. For instance, in the following example, Array with: 10@10 with: 10@60 with: 60@35 with: 10@10 would have provided the same result. The shape argument describes the shape of the polygon and can be set to Complex, Convex, or Nonconvex. Complex specifies that the polygon can be either convex or self-overlapping. Convex specifies that the polygon is one where a straight line connecting any two points of the polygon does not cross any edge. Nonconvex specifies that the polygon is not convex, but that it does not overlap itself. Specifying Complex will draw correctly in all cases. Specifying Convex or Nonconvex can improve drawing performance on some platforms, but the polygon's shape must be known in advance. The following example draws a triangle based on the collection of points provided.

| points |

points := Array with: 10@10 with: 10@60

with: 60@35.

CgWindow default

fillPolygon: CgGC default

points: points

shape: Convex

mode: CoordModeOrigin.

The mode argument can be set to CoordModeOrigin, so that all points are drawn relative to the origin, as in the previous example, or CoordModePrevious, so that all points are drawn relative to the previous point in the collection, as in the following example:

| points |

points := Array with: 10@10

with: 10@60 with: 60@35.

CgWindow default

fillPolygon: CgGC default

points: points

shape: Convex

mode: CoordModePrevious

Last modified date: 04/18/2020