xxxxxxxxxx
let count = 0;
let num = 50;
let r = 20;
let next = 100;
let vecLocation = [];
let vecVelocity = [];
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i = 0; i < num; i++) {
vecLocation[i] = createVector(width / 2, height / 2);
vecVelocity[i] = createVector(random(-10,10), random(-10, 10));
}
}
function draw() {
background(0);
noStroke();
if (count == next)
{
r = random(30);
fill(random(360), random(360), random(360));
count = 0;
}
for (let i = 0; i < num; i++) {
vecLocation[i].add(vecVelocity[i]);
ellipse(vecLocation[i].x, vecLocation[i].y, r, r);
if (vecLocation[i].x > width)
{
vecVelocity[i].x = random(-10, -1);
}
if (vecLocation[i].x < 0) {
vecVelocity[i].x = random(1, 10);
}
if (vecLocation[i].y < 0) {
vecVelocity[i].y = random(1, 10);
}
if (vecLocation[i].y > height) {
vecVelocity[i].y = random(-10, -1);
}
}
count++;
}