Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js | clear() function

Improve Article
Save Article
  • Last Updated : 17 Apr, 2019
Improve Article
Save Article

The clear() function in p5.js is used to clear the pixels within a buffer. This function only clears the canvas. This function clears everything to make all of the pixels 100% transparent. It can be used to reset the drawing canvas.



Parameters: This function does not accept any parameter.

Below program illustrates the clear() function in p5.js:

Example: This example uses clear() function to clear the canvas.

function setup() {
    // Create canvas 
    createCanvas(700, 700);
function draw() {
    // Draw Ellipse at mouseX and mouseY
    ellipse(mouseX, mouseY, 20, 20);
    // Set color of the ellipse
    // Set the text size
    // Set the text
    text("Press Mouse To Clear The Screen", 20, 30);
// Define the mousePressed function
function mousePressed() {

Before Clicking the mouse button:

After Clicking the mouse button:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!