Code

p5.js

Interaction

IntermediatemouseX / mouseY cursor follower, click-spawned ripple rings, and keyPressed() pulse — the three core interaction hooks. p5.js Docs

// Cursor follower
p.ellipse(p.mouseX, p.mouseY, 40, 40);

// Spawn ripples on click
p.mousePressed = () => {
  for (let i = 0; i < 5; i++) {
    ripples.push({
      x: p.mouseX, y: p.mouseY,
      r: i * 8, alpha: 80 - i * 10
    });
  }
};

// Update ripples each frame
for (const rp of ripples) {
  p.ellipse(rp.x, rp.y, rp.r * 2, rp.r * 2);
  rp.r += 3;
  rp.alpha -= 2;
}

// Key events from anywhere
p.keyPressed = () => {
  ripples.push({
    x: p.width / 2, y: p.height / 2,
    r: 0, alpha: 90
  });
};