void setup() { //size(800, 800); fullScreen(); noLoop(); } float branchRatio = 0.7;
void draw() { background(255); stroke(0); noFill(); drawTree(0, width/2, height, radians(-90), height/4); } // draw()
void drawTree(int n, float x, float y, float theta, float len) { float cx = x + len*cos(theta); float cy = y + len*sin(theta); stroke(0); strokeWeight(0.5*n*n); line(x, y, cx, cy);
if (n == 0) { noStroke(); fill(0, random(100, 200), 0); circle(cx, cy, 5); return; } float branchAngle = radians(-30); float bendAngle = radians(random(-15, 15)); drawTree(n-1, cx, cy, theta+branchAngle+bendAngle, len*branchRatio); drawTree(n-1, cx, cy, theta-branchAngle+bendAngle, len*branchRatio); drawTree(n-1, cx, cy, theta+bendAngle, len*branchRatio); }