beginShape()

Draws a polygon with any number of given vertices.

Example

beginShape()
vertex(200, 100)
vertex(300, 150)
vertex(300, 250)
vertex(200, 300)
vertex(100, 250)
vertex(100, 150)
vertex(200, 100)
endShape()

Syntax

beginShape(FORMAT)
...
vertex(x1,y1)
vertex(x2,y2)
vertex(x3,y3)
etc.
...
endShape(MODE)

Description

beginShape() and endShape() allow the drawing of shapes with many corners. After beginShape() is called, corners (vertices) should be listed, each on a separate line. After that, endShape() should be called to end the list. Corners are written in their x,y co-ordinates as vertex(x,y)

The inputs available for beginShape() are:

TESS Connects the edges and creates a closed region. This is the default behavior if nothing was given.

POINTS Draw a set of points

LINES Draw a set of unconnected line segments

TRIANGLES Draw a set of triangles

QUADS Draw a set of quadrilaterals

endShape(CLOSE) connects the last vertex to the first one

endShape()

Find these documents helpful? Let the people who made them help your child learn to code at Strivemath!

We'd love to hear your Feedback/Comments here.

Last updated