pub static redraw: RedrawInternalTypeExpand description
Executes the code within draw() one time. This function allows the program to update the display window only when necessary, for example when an event registered by mousePressed() or keyPressed() occurs.
In structuring a program, it only makes sense to call redraw() within events such as mousePressed(). This is because redraw() does not run draw() immediately (it only sets a flag that indicates an update is needed).
The redraw() function does not work properly when called inside draw().To enable/disable animations, use loop() and noLoop().
In addition you can set the number of redraws per method call. Just add an integer as single parameter for the number of redraws.
Examples
let x = 0;
function setup() {
createCanvas(100, 100);
noLoop();
}
function draw() {
background(204);
line(x, 0, x, height);
}
function mousePressed() {
x += 1;
redraw();
}let x = 0;
function setup() {
createCanvas(100, 100);
noLoop();
}
function draw() {
background(204);
x += 1;
line(x, 0, x, height);
}
function mousePressed() {
redraw(5);
}Parameters
n? Redraw for n-times. The default value is 1.