xxxxxxxxxx
let num = 20;
let vecLocation = [];
let vecVelocity = [];
let fillRed = [];
let fillGreen = [];
let fillBlue = [];
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));
fillRed[i] = Math.floor(Math.random()*2)*255
fillGreen[i]= Math.floor(Math.random()*2)*255
fillBlue[i]= Math.floor(Math.random()*2)*255
}
background(0);
}
function draw() {
// background(0);
noStroke();
let diamiter= 20;
for (let i = 0; i < num; i++) {
fill(fillRed[i],fillGreen[i],fillBlue[i])
vecLocation[i].add(vecVelocity[i]);
ellipse(vecLocation[i].x, vecLocation[i].y, diamiter+i*2,diamiter+i*2);
if (vecLocation[i].x < 0 || vecLocation[i].x > width ) {
vecVelocity[i].x = vecVelocity[i].x * -1;
fillRed[i] = Math.floor(Math.random()*2)*255
fillGreen[i] = Math.floor(Math.random()*2)*255
fillBlue[i] = Math.floor(Math.random()*2)*255
}
if (vecLocation[i].y < 0 || vecLocation[i].y > height) {
vecVelocity[i].y = vecVelocity[i].y * -1;
fillRed[i] = Math.floor(Math.random()*2)*255
fillGreen[i] = Math.floor(Math.random()*2)*255
fillBlue[i] = Math.floor(Math.random()*2)*255
}
}
}