xxxxxxxxxx
let num = 500;
let vecLocation = [];
let vecVelocity = [];
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
for (let i = 0; i < num; i++) {
vecLocation[i] = createVector(width / 2, height / 2);
vecVelocity[i] = createVector(random(-2, 2), random(-2, 2));
}
}
function draw() {
background(255);
noStroke();
for (let i = 0; i < num; i++) {
fill(255, random(100,200), 255);
vecLocation[i].add(vecVelocity[i]);
ellipse(vecLocation[i].x, vecLocation[i].y,5,5);
if (vecLocation[i].x < 0 || vecLocation[i].x > width) {
vecVelocity[i].x = vecVelocity[i].x * -1;
}
if (vecLocation[i].y < 0 || vecLocation[i].y > height) {
vecVelocity[i].y = vecVelocity[i].y * -1;
}
}
}