xxxxxxxxxx
36
let balls = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
//Loop through all of our balls
for (let b = 0; b < balls.length; b++) {
balls[b].move();
balls[b].display();
for (let ob = 0; ob < balls.length; ob++) {
if (ob != b) {
if (balls[b].isNear(balls[ob])) {
background(random(255));
}
}
}
// if(balls[b].isHover()) {
// balls.splice(b, 1);
// }
}
}
function mousePressed() {
balls.push(new Ball(mouseX, mouseY, random(-5, 5), random(-5, 5)));
}
function bounce(pos, low, high, speed) {
if (pos < low || pos > high) {
speed *= -1;
return speed;
} else return speed;
}