WebGraphics.DrawPolygon

From Xojo Documentation

Revision as of 22:02, 22 November 2019 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Method

WebGraphics.DrawPolygon(Points() As Integer)

Supported for all project types and targets.

Draws a polygon using the values in the 1-based array passed as the X and Y coordinates. The polygon is drawn in the current color (specified by ForeColor). Odd numbered array elements are X coordinates and even numbered array elements are Y coordinates.

Example

Polygons are drawn using the DrawPolygon and FillPolygon methods of the WebGraphics class. Polygons are drawn by passing the DrawPolygon or FillPolygon method an Integer array that contains each point in the polygon. This is a 1-based array where odd numbered array elements contain X values and even numbered array elements contain Y coordinates. This means that element 1 contains the X coordinate of the first point in the polygon and element 2 contains the Y coordinate of the first point in the polygon. Consider the following array values:

Element # Value
1 10
2 5
3 40
4 40
5 5
6 60

When passed to the DrawPolygon or FillPolygon method, this array would draw a polygon by drawing a line starting at 10,5 and ending at 40,40 then drawing another line starting from 40,40 ending at 5,60 and finally a line from 5,60 back to 10,5 to complete the polygon. This polygon has only three sets of coordinates so it is a triangle.

This code is in the Paint event of a WebCanvas control:

Var points(6) As Integer
points(1) = 10
points(2) = 5
points(3) = 40
points(4) = 40
points(5) = 5
points(6) = 60
g.DrawPolygon(points)

FillPolygon draws the same polygon but with the interior filled with the ForeColor:

UsersGuide Figure 345a.jpg

Another way of populating the array is with the Array function. The Array function takes a list of values separated by commas and populates the array, beginning with element zero. Since the first element that DrawPolygon uses is element 1, you can use any value in element zero. This code is in the Paint event.

Var points() As Integer
points = Array(0, 10, 5, 40, 40, 5, 60)
g.DrawPolygon(points)