Connect the points to draw a shape.
Are not limited to rectangles, ellipses and regular polygons. shape() allows you to draw any shape you want by connecting points. Shapes are drawn using the current stroke weight and current stroke color, and then filled with the current fill color (unless noStroke()
or noFill()
commands have been run).
Draw a star.
// Draw a star. shape(200, 100, 275, 300, 90, 175, 310, 175, 125, 300);
shape(x1, y1, x2, y2, ..., xn, yn) // Pairs of x,y coordinates. Even number of parameters, four or greater.
Name | Type | Required? | Description |
---|---|---|---|
x1 | Number | The x-location in pixels of the first point of the shape, from left to right on the display. Should be a number from 0 to 400, but negative numbers will locate the point to the left of the display and numbers greater than 400 will locate the point to the right of the display (possibly unseen). | |
y1 | Number | The y-location in pixels of the first point of the shape, from top to bottom on the display. Should be a number from 0 to 400, but negative numbers will locate the point above the display and numbers greater than 400 will locate the point below the display (possibly unseen). | |
x2 | Number | The x-location in pixels of the second point of the shape, from left to right on the display. Should be a number from 0 to 400, but negative numbers will locate the point to the left of the display and numbers greater than 400 will locate the point to the right of the display (possibly unseen). | |
y2 | Number | The y-location in pixels of the second point of the shape, from top to bottom on the display. Should be a number from 0 to 400, but negative numbers will locate the point above the display and numbers greater than 400 will locate the point below the display (possibly unseen). |
No return value. Outputs to the display only.
noFill()
or noStroke()
haven't been called, and where you're trying to draw the shape fits within the coordinates of the display (400 x 400).strokeWeight()
, stroke()
, and fill()
.Found a bug in the documentation? Let us know at documentation@code.org