Skip to content

beginShape()

Begins adding vertices to a custom shape.

The beginShape() and endShape() functions allow for creating custom shapes in 2D or 3D. beginShape() begins adding vertices to a custom shape and endShape() stops adding them.

After calling beginShape(), shapes can be built by calling vertex(), alling endShape() will stop adding vertices to the shape. Each shape will be outlined with the current stroke color and filled with the current fill color.

Transformations such as translate(), rotate(), and scale() don't work between beginShape() and endShape(). It's also not possible to use other shapes, such as ellipse() or rect(), between beginShape() and endShape().

Examples

beginShape example 1

function setup() 
  size(400, 400)
  windowTitle("beginShape() example")

  beginShape()
  vertex(120,80)
  vertex(340, 80)
  vertex(340,300)
  vertex(120,300)
  endShape()

  describe("custom shape with beginShape() function, vertices and endShape()")
end

beginShape example 2

function setup() 
  size(400, 400)
  windowTitle("beginShape() example")

  fill(0)
  beginShape()
  for i=0,10 do
    vertex(random(width),random(height))
  end
  endShape()
  describe("custom shape with beginShape() function, vertices and endShape()")
end