xxxxxxxxxx
int depth = 15;
float strtLen = 60;
void setup() {
size(550, 550);
noLoop();
}
void draw() {
background(255);
drawPaper();
// startX, startY, initial angle, initial branch (trunk) length, recursion control
branch(width/2, height-100, -random(1.4, 1.74), strtLen, depth);
noFill();
stroke(180);
strokeWeight(1);
rect(0, 0, width-1, height-1);
}
void branch(float x, float y, float ang, float len, int d) {
float x2 = x;
float y2 = y;
x += cos(ang) * len;
y += sin(ang) * len;
if (d == 1) {
noStroke();
if (len > 4.0) {
fill(#F0B102);
ellipse(x2, y2, 2, 4);
} else if ( len <= 4.0) {
fill(#E80E02);
ellipse(x2, y2, 3, 1);
}
} else {
drawLine(x2, y2, x, y, len);
}
len *= random(0.7, 0.94);
d--;
if (d > 0) {
branch(x, y, ang - random(0.2, 0.6), len, d);
branch(x, y, ang + random(0.2, 0.6), len, d);
}
}
void drawLine(float strtx, float strty, float finx, float finy, float sw) {
int numSegs = 15;
float fraction = 0;
int divBy = numSegs;
float x1 = strtx;
float y1 = strty;
stroke(60);
noFill();
strokeWeight(sw * 0.05);
beginShape();
for (int j = 0; j <= int (numSegs); j++) {
float x = (randomGaussian()*.3) + x1 + (fraction * (finx-x1));
float y = (randomGaussian()*.3) + y1 + (fraction * (finy-y1));
vertex(x, y);
x1 = x;
y1 = y;
fraction = 1.0/divBy--;
}
endShape();
}
void drawPaper() {
noStroke();
for (int i = 0; i<width; i+=2) {
for (int j = 0; j<height; j+=2) {
fill(random(210,235), 150);
rect(i, j, 2, 2);
}
}
for (int i = 0; i<30; i++) {
fill(random(70,100), 150);
ellipse(random(0, width), random(0, height), random(1, 3), random(1, 3));
}
}
void mousePressed() {
redraw();
}