xxxxxxxxxx
let vecLocation = [];
let vecVelocity = [];
let diameter = [];
let r = [];
let g = [];
let b = [];
const NUM = 50;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
for(let i = 0; i < NUM; i++){
vecLocation[i] = createVector(width/2, height-100);
vecVelocity[i] = createVector(random(-5, 5), random(-5, -10));
diameter[i] = random(20, 50);
r[i] = random(200, 255);
g[i] = random(0, 255);
b[i] = random(0, 255);
}
}
function draw() {
background(255, 240, 240);
//ふた
stroke(255, 100, 100, 200);
line(width/2-100, height-100, width/2-150, height-50)
line(width/2+100, height-100, width/2+150, height-50)
//箱
noStroke();
fill(255, 100, 100, 200);
rect(width/2-100, height-100, 200, 100);
for(let i = 0; i < NUM; i++){
fill(r[i], g[i], b[i]);
ellipse(vecLocation[i].x, vecLocation[i].y, diameter[i], diameter[i]);
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 < 0 || vecLocation[i].y > height){
vecVelocity[i].y = vecVelocity[i].y * -1;
}
}
}