isLooping

Static isLooping 

Source
pub static isLooping: IsLoopingInternalType
Expand description

By default, p5.js loops through draw() continuously, executing the code within it. If the sketch is stopped with noLoop() or resumed with loop(), isLooping() returns the current state for use within custom event handlers.

Examples

let checkbox, button, colBG, colFill;

function setup() {
  createCanvas(100, 100);

  button = createButton('Colorize if loop()');
  button.position(0, 120);
  button.mousePressed(changeBG);

  checkbox = createCheckbox('loop()', true);
  checkbox.changed(checkLoop);

  colBG = color(0);
  colFill = color(255);
}

function changeBG() {
  if (isLooping()) {
    colBG = color(random(255), random(255), random(255));
    colFill = color(random(255), random(255), random(255));
  }
}

function checkLoop() {
  if (this.checked()) {
    loop();
  } else {
    noLoop();
  }
}

function draw() {
  background(colBG);
  fill(colFill);
  ellipse(frameCount % width, height / 2, 50);
}