xxxxxxxxxx
let veclocation=[];
let vecvelocity=[];
const NUM = 40;
function setup() {
createCanvas(windowWidth,windowHeight);
frameRate(100);//=60fps=frame per second
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(100,200,200);
noStroke();
fill(random(255), random(255), random(255), random(300));
for(let i = 0; i < NUM; i++){
ellipse(veclocation[i].x, veclocation[i].y, random(100), random(100));
veclocation[i].add(vecvelocity[i]);
if(veclocation[i].x > width || veclocation[i].x < 0){
vecvelocity[i].x = vecvelocity[i].x * -1;
}
if(veclocation[i].y > height || veclocation[i].y < 0){
vecvelocity[i].y = vecvelocity[i].y * -1;
}
}
}