draw()

Renders to the canvas repeatedly, frame by frame

Example

def setup():
  createCanvas(400,400)

def draw():
  background("grey")
  fill(255,79,132)
  circle(mouseX,mouseY,100)

Syntax

draw()

Description

The draw() function is automatically called continuously at a fixed time interval (by default, 60 times per second) as long as the program is running. It is first called immediately after the setup() function.

The number of times draw() executes in each second may be controlled with the frameRate() function.

Inside the draw() function, you can use a variety of p5 Python functions to draw shapes, lines, and text on the canvas, as well as manipulate the color, position, and size of these elements. You can also use variables to create animations or interactive elements that respond to user input.

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