木2
function setup() {
createCanvas(800, 600);
background(255);
stroke(0);
translate(width / 2, height);
branch(200);
}
function branch(len) {
strokeWeight(map(len, 10, 200, 1, 10)); // 幹の太さを設定
line(0, 0, 0, -len);
translate(0, -len);
if (len > 5) {
push();
rotate(PI / 7 + random(-0.1, 0.1)); // ランダムな角度
branch(len * 0.71 + random(-2, 2)); // ランダムな長さ
pop();
push();
rotate(-PI / 4 + random(-0.1, 0.1)); // ランダムな角度
branch(len * 0.67 + random(-2, 2)); // ランダムな長さ
pop();
} else {
// 葉を描画
fill(34, 137, 34); // 葉の色を設定
ellipse(0, 0, 6, 15); // 葉を描画
noFill();
}
}
よろしければサポートお願いします!