Skip to content
Advertisement

p5.js how to freeze canvas?

I try to do something like that :

JavaScript
JavaScript

But i want to “freeze” this canvas, so if i load the page i will have 30 rect() at a random height between 30 and 120.

Advertisement

Answer

One option would be to use noLoop() method inside setup function that will stop draw method loop.

JavaScript
JavaScript

Note that with using noLoop and loop methods, you can toggle draw loop on some event for example mousePressed like this.

JavaScript
JavaScript

Other option is to create bars array once in setup function and then show them with draw method. This way you don’t have to stop draw loop.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement