let forêt = [];
let nArbre;
let t;
let c;
function setup() {
c = 600;
cnv = createCanvas(c, c);
nArbre = int(random(5, 40));
for (let i = 0; i < nArbre; i++) {
forêt.push(new Arbre(height / 3 + (i * height) / (1.5 * nArbre), i));
}
c = createVector(random(10, 60), random(10, 60), random(10, 60));
noStroke();
}
function draw() {
background(c.x, c.y, c.z);
t = frameCount / 1000;
for (let i = 0; i < nArbre; i++) {
forêt[i].display();
}
}
class Arbre {
constructor(dy, i) {
this.x = random(0, c);
this.thickness = random(15, 25);
this.dy = dy;
this.bend1 = random(2, 10);
this.bend2 = random(2, 10);
this.brouillard = [];
this.fCount = int(random(50, 100 + 5000 / nArbre));
for (let k = 0; k < this.fCount; k++) {
this.brouillard[k] = createVector(
random(50, c / 2),
random(2, 5),
random(20, 100)
);
}
this.shape = [];
for (let k = 0; k <= this.dy; k++) {
this.shape[k] = createVector(
this.x +
(this.thickness / this.bend2) *
sin(k / this.brouillard[30].x + this.dy) +
(this.thickness / this.bend2 / 2) *
sin(k / this.brouillard[20].x - this.dy) -
(this.thickness / this.bend1) * cos(this.dy - k / 50),
k
);
}
}
display() {
fill(c.x, c.y, c.z);
beginShape();
for (let i = 0; i <= this.dy; i++) {
vertex(this.shape[i].x, this.shape[i].y);
}
for (let i = this.shape.length - 1; i >= 0; i--) {
vertex(this.shape[i].x - this.thickness - i / 80, this.shape[i].y);
}
endShape();
fill(255, 255, 255, 2);
for (let i = 0; i < this.fCount; i++) {
circle(
this.x + this.brouillard[i].x * sin(t + this.x + i * this.dy),
this.dy -
i / this.bend1 -
this.thickness * 5 * abs(sin(t + i + this.x)),
this.brouillard[i].z
);
circle(
this.x + this.brouillard[i].x * sin(t + this.x + i * this.dy),
this.dy -
i / this.bend1 -
this.thickness * 7 * abs(sin(t + i + this.x)),
this.brouillard[i].z
);
}
}
}
function mousePressed() {
forêt = [];
setup();
draw();
}