Try now in the
Open Cloud »
(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:

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

 In[1]:= XGraphics[Polygon[{{0, 0}, {2, 0}, {0, 1}}]]
 Out[1]=

Turn on axes so you can see the coordinate values:

 In[2]:= XGraphics[Polygon[{{0, 0}, {2, 0}, {0, 1}}], Axes -> True]
 Out[2]=

 In[1]:= XGraphics[Polygon[{{0, 0}, {2, 0}, {0, 1}}]]
 Out[1]=

Draw a house shape. Try drawing other shapes:

Get particular shapes by choosing appropriate coordinate values:

 In[1]:= XGraphics[Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]]
 Out[1]=

It may help to turn on the axes:

 In[2]:= XGraphics[Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}], Axes -> True]
 Out[2]=

 In[1]:= XGraphics[Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]]
 Out[1]=

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

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

 In[1]:= XGraphics[{Red, Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]}]
 Out[1]=

 In[1]:= XGraphics[{Red, Polygon[{{0, 0}, {2, 0}, {2, 2}, {1, 3}, {0, 2}}]}]
 Out[1]=