Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »
Try it now »
(no sign-in required)

Draw a Polygon

Get started with 2D graphics by drawing a polygon.

Run the code to draw a polygon. Try other coordinate values:

SHOW/HIDE DETAILS

Draw a polygon with vertices at coordinate positions {0,0}, {2,0}, and {0,1}:

Graphics[Polygon[{{0, 0}, {2, 0}, {0, 1}}]]

Turn on axes so you can see the coordinate values:

Graphics[Polygon[{{0, 0}, {2, 0}, {0, 1}}], Axes -> True]

HIDE DETAILS
Graphics[Polygon[{{0, 0}, {2, 0}, {0, 1}}]]

Draw a house shape. Try drawing other shapes:

SHOW/HIDE DETAILS

Get particular shapes by choosing appropriate coordinate values:

Graphics[Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]]

It may help to turn on the axes:

Graphics[Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}], Axes -> True]

HIDE DETAILS
Graphics[Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]]

Make it red. Try other colors, like Orange or Green:

SHOW/HIDE DETAILS

Make the polygon red. Enclose the color and polygon in a list (indicated by the curly braces):

Graphics[{Red, Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]}]

HIDE DETAILS
Graphics[{Red, Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]}]