P5 Python Docs
  • Getting Started
  • Simple mode
  • Reference
    • Shapes
      • 2D
        • point()
        • line()
        • rect()
        • square()
        • triangle()
        • circle()
        • ellipse()
        • arc()
        • quad()
        • beginShape()
      • 3D
        • plane()
        • box()
        • sphere()
        • cone()
        • cylinder()
        • ellipsoid()
        • torus()
    • Controlling the environment
      • coordinateMode()
      • rectMode()
      • ellipseMode()
      • frameRate()
      • setup()
      • draw()
    • Built-in Variables
      • Environment
      • Keyboard
      • Mouse
    • Built-in Functions
      • keyIsDown()
      • millis()
      • second()
      • minute()
      • hour()
      • translate()
      • rotate()
      • createSlider()
      • createGraphics()
      • createVector()
    • Events
      • Keyboard
        • keyPressed()
        • keyReleased()
      • Mouse
        • mouseMoved()
        • mouseDragged()
        • mousePressed()
        • doubleClicked()
        • mouseWheel()
    • Text
      • text()
      • textSize()
      • textAlign()
    • Math
      • drawTickAxes()
      • random()
      • randomGaussian()
      • dist()
      • linmap()
      • bounce()
      • wave()
    • Colour and Outline
      • colorMode()
      • fill()
      • stroke()
      • strokeWeight()
      • background()
    • Images & Audio
      • loadImage() and image()
      • loadSound()
    • 3D Controls
      • orbitControl()
      • translate()
      • rotateZ()
      • rotateX()
      • rotateY()
      • scale()
Powered by GitBook
On this page
  • Example
  • Syntax
  • Description
  1. Reference
  2. Shapes
  3. 2D

beginShape()

Draws a polygon with any number of given vertices.

Previousquad()Next3D

Last updated 2 years ago

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)
Input
Description

beginShape()

starts the list of co-ordinates

FORMAT

contains any of POINTS, LINES, TRIANGLES, QUADS, TESS, see Description

vertex(xi,yi)

The coordinates of the i-th vertex of the polygon

endShape()

ends the list of co-ordinates

MODE

CLOSE or nothing

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 !

We'd love to hear your Feedback/Comments .

Strivemath
here