xxxxxxxxxx
let vecLocation = [];
let vecVelocity = [];
const NUM = 2;
let cls = [];
let size = [];
function setup() {
createCanvas(windowWidth, windowHeight);
for(let i = 0; i < 3; i++){
cls[i] = random(0,255)
}
for(let i = 0; i < NUM; i++){
vecLocation[i] = createVector(width / 2, height / 2);
vecVelocity[i] = createVector(random(-10,10),random(-10,10));
}
for(let i = 0; i < 2; i++){
size[i] = 20;
}
}
function draw() {
background(0);
fill(cls[0],cls[1],cls[2],200)
rect(30,30,width - 60,height - 60)
noStroke()
fill(255);
for(let i = 0; i < NUM; i++){
ellipse(vecLocation[i].x, vecLocation[i].y,size[i],size[i]);
vecLocation[i].add(vecVelocity[i]);
if(vecLocation[i].x >= width - 50 || vecLocation[i].x <= 50){
rnd = random(0.5,1.5);
vecVelocity[i].y = vecVelocity[i].y * rnd;
vecVelocity[i].x = vecVelocity[i].x * rnd;
vecVelocity[i].x = vecVelocity[i].x * -1;
for(let i = 0; i < 3; i++){
cls[i] = random(0,255)
}
size[i] = random(10,30)
}
if(vecLocation[i].y >= height - 50 || vecLocation[i].y <= 50){
rnd = random(0.5,1.5);
vecVelocity[i].x = vecVelocity[i].x * rnd;
vecVelocity[i].y = vecVelocity[i].y * rnd;
vecVelocity[i].y = vecVelocity[i].y * -1;
for(let i = 0; i < 3; i++){
cls[i] = random(0,255)
}
size[i] = random(10,30)
}
}
}