xxxxxxxxxx
24
let particles = [];
function setup() {
createCanvas(400, 300);
}
// define a function that creates new bubbles when the mouse is pressed
function mousePressed() {
particles.push(new Particle(mouseX, mouseY));
}
function draw() {
background(105, 255, 200);
for (let i = 0; i < particles.length; i++) {
let p = particles[i];
p.move();
p.display();
}
// if more than 3 bubbles are pressed into existence, then use splice to only allow the two old bubbles and the new bubble to be displayed
if (particles.length > 3) {
particles.splice(0, 1);
}
}