xxxxxxxxxx
const 木 = (x, y, z) => ({
x: random(width) - width / 2,
y: random(height / 2),
z: random(5),
});
const 林 = {
林: [],
初期化() {
for (let i = 100; i--; ) {
this.林.push(木());
}
},
更新() {
for (const 木 of this.林) {
木.x -= (mouseX - width / 2) * 0.025;
if (木.x > width / 2) 木.x = -width / 2;
if (木.x < -width / 2) 木.x = width / 2;
const my = constrain(mouseY, 0, height);
木.z -= log(1 + my) / 200;
if (木.z < 0) 木.z = 5;
}
this.林.sort((木1, 木2) => (木1.z > 木2.z ? -1 : 1));
},
影を描く() {
fill('black');
noStroke();
for (const 木 of this.林) {
rect(木.x / 木.z, 50 / 木.z, (-木.y / 木.z) * 0.6, -2);
}
},
林を描く() {
fill(' rgb(122,65,15)');
stroke('black');
for (const 木 of this.林) {
rect(木.x / 木.z, 50 / 木.z, 16 / 木.z, -木.y / 木.z);
}
},
};
setup = () => {
createCanvas(900, 600);
林.初期化();
};
draw = (_) => {
background('green');
translate(width / 2, height / 2);
林.更新();
林.影を描く();
林.林を描く();
};