xxxxxxxxxx
32
let circles = []
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 5; i++) {
r = random(10, 15);
circles[i] = new Circle(random(r, width - r), random(r, height - r), r);
}
}
function switch_circles(c) {
for (let rest of circles) {
if (c !== rest && c.intersects(rest)) {
c.dir_x *= -1;
c.dir_y *= -1;
rest.dir_x *= -1;
rest.dir_y *= -1;
let temp_color = c.color;
c.color = rest.color;
rest.color = temp_color;
}
}
}
function draw() {
background(0);
for (let c of circles) {
c.draw();
c.move();
switch_circles(c);
}
}