xxxxxxxxxx
35
var balls = [];
var iterations = 10;
function setup() {
createCanvas(640, 480);
// for (var i = 0; i < 10; i++) {
// balls[i] = new Circle(random(20, width - 20), random(20, height - 20), 10);
// }
}
function mousePressed() {
balls.push(new Circle(mouseX, mouseY, 20));
}
function draw() {
background(0);
if (frameCount % 20 == 0) {
balls.push(new Circle(width / 2, height / 2, 20));
}
if (balls[0]) {
for (var ball of balls) {
var g = createVector(0, 0.25);
ball.applyForce(g);
for (var i = 0; i < iterations; i++) {
ball.update();
}
for (var other of balls) {
if (other != ball) {
ball.collideCircle(other);
}
}
ball.show();
}
}
}