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.
ellipse(mouseX, mouseY, 20, 20);
"Press Mouse To Clear The Screen"
, 20, 30);
Before Clicking the mouse button:
After Clicking the mouse button:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!