xxxxxxxxxx
let NUM = 20;
let vecLocation = [];
let vecVelocity = [];
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
frameRate(60);
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();
fill(0,127,255);
for (let i = 0; i<NUM;i++){
vecLocation[i].add(vecVelocity[i]);
ellipse(vecLocation[i].x,vecLocation[i].y,20,20);
if(vecLocation[i].x < random(0,width/3) || vecLocation[i].x > random(width*2/3,width)){
vecVelocity[i].x = vecVelocity[i].x * -1;
}
if(vecLocation[i].y < random(0,height/3) || vecLocation[i].y >random(height*2/3,height)){
vecVelocity[i].y = vecVelocity[i].y * -1;
}
}
}