xxxxxxxxxx
let num=300;//円の数
let vecLocation=[];//円の中心ベクトル
let vecVelocity=[];//円の速度ベクトル
function setup() {
createCanvas(windowWidth, windowHeight);
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();//枠線なし
//円の数だけ繰り返す
for (let i=100; i<num; i++){
vecLocation[i].add(vecVelocity[i]);//円の座標を更新
fill(125,random(125,255),random(0,255));//塗りの色をランダムに
ellipse(vecLocation[i].x,vecLocation[i].y,20,20);//指定位置に円を描写
if(vecLocation[i].x<0||vecLocation[i].y>width){
vecVelocity[i].x=vecVelocity[i].x*-1;
}
if(vecLocation[i].y<0||vecLocation[i].y>height){
vecVelocity[i].y=vecVelocity[i].y*-1;
}
}
}