Skip to content
Advertisement

How can I clear/reset the canvas with a counter or countdown in Processing?

I would like to know how can I set a reset loop: While the draw() is going on I would like to clear the canvas so I can start to draw on a clean canvas again and again.

(I don’t want to use keyPressed() or mousePressed() it has to be automatic)

JavaScript

Thank you for your help in advice!

Advertisement

Answer

You can simply clear the background again, for example when you press a key:

JavaScript

You can do the same on some other event (amount of time, loudness, etc.)

Here’s an example based on your code that clears the background every 3 seconds:

JavaScript

For more info on millis() for a delay see this answer

Another option is to do the calculation frame based using frameCount. For example if the sketch’s frameRate is about 60 fps and you want to clear roughly every 3 seconds you can check if the multiples of 180 (3 * 60) frames passed in tandem with the modulo(%) operator

JavaScript
Advertisement