xxxxxxxxxx
let num = 100; //円の数
let vecLocation = []; //円の中心の位置ベクトル
let vecVelocity = []; //円の速度ベクトル
let fill_col = [];
let r = [];
let movement = [];
let movement_1 = [];
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));
fill_col[i] = color(random(255), random(255), random(255), random(150,255));
r[i] = random(10, 50);
movement_1[i] = random(10);
}
}
function draw() {
background(0); //背景を描画
noStroke(); //枠線なし
ball_num = random(100);
movement_1 = random(windowHeight/random(10, 20));
movement_2 = random(windowWidth/random(10, 50));
//円の数だけくりかえす
for (let i = 0; i < num; i++) {
fill(fill_col[i]);
vecLocation[i].add(vecVelocity[i]); //円の座標を更新
ellipse(vecLocation[i].x, vecLocation[i].y, r[i], r[i]); //指定した位置に円を描画
if (vecLocation[i].x < 0 || vecLocation[i].x > width) { //もし画面の左端、または右端に到達したら
vecVelocity[i].x = vecVelocity[i].x * -1; //X方向のスピードを反転
}
if (vecLocation[i].y < 0 || vecLocation[i].y > height) { //もし画面の下端、または上端に到達したら
vecVelocity[i].y = vecVelocity[i].y * -1; //Y方向のスピードを反転
}
if (movement_1 > random(windowWidth)) {
vecVelocity[i].x = vecVelocity[i].x* -1;
}
if (movement_2 < random(windowWidth/100)){
vecVelocity[i].x = vecVelocity[i].x* 1.0008;
}else{
vecVelocity[i].x = vecVelocity[i].x- 0.001;
}
if (movement_2 > random(windowHeight)) {
vecVelocity[i].y = vecVelocity[i].y* -1;
}
if (movement_1 < random(windowHeight/70)){
vecVelocity[i].y = vecVelocity[i].y* 1.0004;
}else{
vecVelocity[i].y = vecVelocity[i].y+ 0.001;
}
}
}