p5.js | loop() Function
The loop() function is used to call draw() function continuously. The loop() function can be stopped using noLoop() function.
Syntax:
loop()
Below example illustrates the loop() function in p5.js:
Example:
let l = 0; function setup() { // Create canvas of given size createCanvas(500, 300); // Set the background color background('green'); } function draw() { // Set the stroke color stroke('white'); l = l + 0.5; if (l > width) { l = 0; } // Function to draw the line line(l, 0, l, height); } function mousePressed() { noLoop(); } function mouseReleased() { loop(); } |
chevron_right
filter_none
Output:

Recommended Posts:
- JavaScript | While Loop
- JavaScript | For Loop
- How to use loop through an array in JavaScript?
- How to loop through an associative array and get the key in PHP?
- HTML | loop Attribute
- Determine the first and last iteration in a foreach loop in PHP?
- HTML | <audio> loop Attribute
- HTML | <video> loop Attribute
- PHP | Separate odd and even elements from array without using loop
- HTML | DOM Video loop Property
- How to break nested for loop using JavaScript?
- HTML | DOM Audio loop Property
- How to remove an array element in a foreach loop?
- Asynchronous Functions and the Node Event Loop
- Iterate associative array using foreach loop in PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



