Skip to content

Commit e341b21

Browse files
authored
Merge pull request #1185 from Divyansh013/main
Improved loop example
2 parents 639c167 + f028503 commit e341b21

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/data/examples/en/00_Structure/05_Loop.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/*
22
* @name Loop
33
* @arialabel Horizontal white line on a black background that moves from the bottom to the top of the screen parallel to the x-axis
4-
* @description The code inside the draw() function runs continuously from top
5-
* to bottom until the program is stopped.
4+
* @description If noLoop() is run in setup(), the code in draw()
5+
* is only run once. In this example, click the mouse
6+
* to run the loop() function to cause the draw() the
7+
* run continuously.
68
*/
7-
let y = 100;
9+
let y = 0;
810

911
// The statements in the setup() function
1012
// execute once when the program begins
1113
function setup() {
1214
createCanvas(720, 400); // Size must be the first statement
1315
stroke(255); // Set line drawing color to white
1416
frameRate(30);
17+
noLoop();
1518
}
1619
// The statements in draw() are executed until the
1720
// program is stopped. Each statement is executed in
@@ -25,3 +28,7 @@ function draw() {
2528
}
2629
line(0, y, width, y);
2730
}
31+
32+
function mousePressed(){
33+
loop();
34+
}

0 commit comments

Comments
 (0)