xxxxxxxxxx
let w;
let h;
let vecLocation = [];
let vecVelocity = [];
const NUM = 100; //定数
let size = [];
let col = [];
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(50);
w = windowWidth;
h = windowHeight;
for(let i = 0; i < NUM; i++){
vecLocation[i] = createVector(w/2, h/2);
vecVelocity[i] = createVector(random(-10, 10), random(-10,10));
col[i] = color(random(255), random(255), random(255), random(150,255));
size[i] = random(10,60);
}
}
function draw() {
background(0);
noStroke();
w = windowWidth;
h = windowHeight;
for(let i=0; i < NUM; i++){
fill(col[i])
ellipse(vecLocation[i].x , vecLocation[i].y , size[i], size[i]);
vecLocation[i].add(vecVelocity[i]);
if( vecLocation[i].x> w || vecLocation[i].x <0) {
vecVelocity[i].x= vecVelocity[i].x * -1;
}
if( vecLocation[i].y> h || vecLocation[i].y < 0) {
vecVelocity[i].y = vecVelocity[i].y * -1;
}
}
}