xxxxxxxxxx
62
let particles = [];
let sky;
function setup() {
createCanvas(800, 600);
particles = [];
for (let j = 0; j < height; j++) {
let c = lerpColor(color(21, 122, 188), color(102, 185, 240), j / height);
stroke(c);
line(0, j, width, j);
}
for (let i = 0; i < 5; i++) {
particles.push(new Particle(random(width), random(height), random(25, 100)));
}
}
function draw() {
for (let i = particles.length - 1; i >= 0; i--) {
let p = particles[i];
if (!p.render) {
p.drawParticle();
p.more();
} else {
particles.splice(i, 1);
}
}
}
class Particle {
constructor(x, y, r) {
this.position = createVector(x, y);
this.r = r;
this.render = false;
}
more() {
if (this.r > 2) {
let num = Math.floor(random(1, 4));
for (let i = 0; i < num; i++) {
let newX = this.position.x + random(-this.r, this.r);
let newY = this.position.y + random(-this.r / 2, this.r / 4);
let r = random(10);
let newR = this.r - r;
if (newR < 1) {
newR = 1;
}
particles.push(new Particle(newX, newY, newR));
this.render = true;
}
} else {
this.render = true;
}
}
drawParticle() {
noStroke();
fill(255, 10);
circle(this.position.x, this.position.y, this.r);
}
}