Redraw
The redraw() function makes draw() execute once. In this example, draw() is executed once every time the mouse is clicked.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
let y;
// The statements in the setup() function
// execute once when the program begins
function setup() {
createCanvas(720, 400);
stroke(255);
noLoop();
y = height * 0.5;
}
// The statements in draw() are executed until the
// program is stopped. Each statement is executed in
// sequence and after the last line is read, the first
// line is executed again.
function draw() {
background(0);
y = y - 4;
if (y < 0) {
y = height;
}
line(0, y, width, y);
}
function mousePressed() {
redraw();
}