xxxxxxxxxx
31
let loc = [];
let vel = [];
let diameter = [];
const NUM = 100;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
for (let i = 0; i < NUM; i++) {
loc[i] = createVector(width / 2, height / 2);
vel[i] = createVector(random(-10, 10), random(-10, 10));
diameter[i] = random(10, 40);
}
}
function draw() {
background(0);
noStroke();
fill(0, 127, 255);
for (let i = 0; i < NUM; i++) {
loc[i].add(vel[i]);
circle(loc[i].x, loc[i].y, diameter[i]);
if (loc[i].x < 0 || loc[i].x > width) {
vel[i].x = vel[i].x * -1;
}
if (loc[i].y < 0 || loc[i].y > height) {
vel[i].y = vel[i].y * -1;
}
}
}