<div class="meta" robots="noindex">

</div>

Method

# Graphics.DrawPolygon

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r1. Please use `Graphics.DrawPath<graphics.drawpath>` as a replacement.

</div>

## Description

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. The current color is set with the `Graphics.DrawingColor<graphics.drawingcolor>` property.

## Notes

Odd numbered array elements are X coordinates and even numbered array elements are Y coordinates.

## Sample code

Polygons are drawn using the <span class="title-ref">DrawPolygon</span> and FillPolygon methods of the `Graphics</api/graphics/graphics>` class. Polygons are drawn by passing the <span class="title-ref">DrawPolygon</span> or FillPolygon method an `Integer</api/data_types/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:

{\| cellpadding="8" cellspacing="0" border="1" ! width=30% style="background-color:#e0e0e0" Value 1 -5 3 -40 5 -60 \|}

When passed to the <span class="title-ref">DrawPolygon</span> 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.

The code in the Paint event of a `Canvas</api/deprecated/canvas>` control or `Window</api/deprecated/window>` to draw this polygon, looks like this. The code is in the Paint event.

``` xojo
Var points(6) As Double 
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:

> ![image](images/graphics.drawpolygon_usersguide_figure_345a.jpg)

Another way of populating the array is with the `Array</api/language/array>` function. The `Array</api/language/array>` function takes a list of values separated by commas and populates the array, beginning with element zero. Since the first element that <span class="title-ref">DrawPolygon</span> uses is element 1, you can use any value in element zero. This code is in the Paint event.

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

## Compatibility

All project types on all supported operating systems.
