# Tree Fractal

This is a tree fractal. Fractals are mathematical sets that have a repeating pattern at every scale. Each branching point on the tree branches off at the same angle

The images above of the tree fractal were created in processing. Source code can be seen below.

```//angle that stem one branches off at
float rotationStem1 = - QUARTER_PI / 5;
//angle that stem two branches off at
float rotationStem2 = QUARTER_PI / 5;
//begining branch length
float lineLength = 200;
//depth to generate tree to
int depth = 5;

void setup() {
size(960, 640, P3D);
frameRate(30);
}

void draw() {
background(255);
strokeWeight(2);
smooth();
//draw starting trunk
line(width/2, height - 10, width/2, height - 10 - lineLength);
translate(width/2, height - 10 +- lineLength);
rotateZ(PI);
//draw stems
drawStem(0, lineLength / 3 * 2);

//change rotation
rotationStem1 -= 0.01;
rotationStem2 += 0.01;
}

//stems recursively
void drawStem(int i, float lengthL) {
//draw stem one
rotateZ(rotationStem1);
line(0,0, 0, lengthL);
translate(0, lengthL);
if (i < depth)
drawStem(i+1, lengthL / 3 * 2); //draw stems that branch off and decrease length

translate(0, -lengthL);
rotateZ(-rotationStem1);

//draw stem two
rotateZ(rotationStem2);
line(0,0, 0, lengthL);
translate(0, lengthL);
if (i < depth)
drawStem(i+1, lengthL / 3 * 2);//draw stems that branch off and decrease length

translate(0, -lengthL);
rotateZ(-rotationStem2);
}
```

Fractals: Click Here

Comment