xxxxxxxxxx
//disable right click menu
document.oncontextmenu = function() {
return false;
};
let bubbles = new Array(100);
let force = 2500;
function setup() {
createCanvas(700, 700);
for (let i = 0; i < bubbles.length; i++) {
bubbles[i] = new Bubble(random(0, width), random(0, height), random(200, 2000));
}
strokeWeight(3);
stroke(43, 32, 40);
fill(235,144,29, 220);
background(69,104,108);
}
function draw() {
background(69,104,108, 20);
bubbles.forEach(i => {
i.update();
i.display();
});
if (mouseIsPressed) {
let mouse = createVector(mouseX, mouseY);
bubbles.forEach(bubble => {
let f;
if (mouseButton === LEFT) {
f = p5.Vector.sub(bubble.p, mouse);
} else {
f = p5.Vector.sub(mouse, bubble.p);
}
let dist = p5.Vector.mag(f);
f.normalize();
f.mult(force);
f.div(dist);
bubble.force(f);
});
}
}