この記事を書いた人

- クリエイティブコーディングで制作した作品と、上達のためにやったこと・学習過程を発信
- コンセプトは「クリエイティブコーディング1万時間の歩き方」
- 2024年にProcessingの構文のアウトプットを終え、2025年から作品制作開始(クリエイティブコーディングで作成した作品集)
目次
作品の画像とコード
【作品No.16】カラフルな雨

アニメーション。
// 参考にさせていただいたページとURL
// rain
//https://editor.p5js.org/kelsierose94/sketches/MU2Y21aG0
var drop = [];
let colors = ["#f94144","#f3722c","#f8961e","#f9844a","#f9c74f","#90be6d","#43aa8b","#4d908e","#577590","#277da1"] // 色の配列を追加
function setup() {
createCanvas(400, 400);
background(255); // 背景色を白に設定
for (var i = 0; i < 150; i++) {
drop[i] = new Drop();
}
}
function draw() {
background(255); // 背景色を適用
for (var i = 0; i < 150; i++) {
drop[i].show();
drop[i].update();
}
}
function Drop() {
this.x = random(0, width);
this.y = random(0, -height);
this.color = color(colors[int(random(colors.length))]); // 色をランダムに選択
this.size = random(20, 50);
this.show = function () {
noStroke();
fill(this.color);
ellipse(this.x, this.y, this.size, this.size);
};
this.update = function () {
this.speed = random(5, 10);
this.gravity = 1.05;
this.y = this.y + this.speed * this.gravity;
this.size = this.size * 0.98; // サイズを少しずつ小さくする
if (this.y > height) {
this.y = random(0, -height);
this.size = random(20, 50); // リセット時にサイズを元に戻す
this.gravity = 0;
}
}
}
感想
カラフルな雨が降ったら、雨が好きになる。

それでは今日もレッツワクワクコーディング。