Ichthyarchy: The Domain of Fishes

For completeness’ sake we can also have multiple global mode sketches as long as they live in separate <iframe>:
https://developer.Mozilla.org/en-US/docs/Web/HTML/Element/iframe

Using a more p5js style, we can call p5.Element::mousePressed() method over the p5.Renderer object returned by createCanvas(), and then apply noLoop() or loop() to the sketch inside its callback:


Global Mode Version:

var paused;

function setup() {
  createCanvas(800, 600).mousePressed(togglePause);
  frameRate(2);
}

function draw() {
  background('#' + hex(~~random(0x1000), 3));
}

function togglePause() {
  if (paused ^= true)  noLoop();
  else                 loop();
}

Instance Mode Version:

new p5(p => {
  var paused;

  p.setup = function () {
    p.createCanvas(800, 600).mousePressed(togglePause);
    p.frameRate(2);
  };

  p.draw = function () {
    p.background('#' + p.hex(~~p.random(0x1000), 3));
  };

  function togglePause() {
    if (paused ^= true)  p.noLoop();
    else                 p.loop();
  }
});