Introduction to Programming Winter Term 14/15 Lecture 11 Fractal Tree Example

Einführung in die Programmierung, WS1415

Sorry, recording the screen cast did not work.

Instead find the source code of the FractalTree from the lecture here:

package de.uks.ep1415.m1234567.ha11;

import processing.core.PApplet;

public class FractalTree extends PApplet
{
   @Override
   public void setup()
   {
      size(400, 600);
   }
   
   float totalSize = 5;
   
   @Override
   public void draw()
   {
      background(255);
      
      drawTree(200, 550, PI/2, totalSize);
      
      totalSize++;
   }

   private void drawTree(float rootX, float rootY, float angle, float size)
   {
      float topX = rootX + size * cos(angle);
      float topY = rootY - size * sin(angle);
      
      stroke(139,69,19);
      strokeWeight(size / 20);
      line(rootX, rootY, topX, topY);
      
      noStroke();
      fill(0, 255, 0);
      ellipse(topX, topY, 10, 10);
      
      if (size >= 10)
      {
         drawTree((topX+rootX)/2, (topY+rootY)/2, angle-PI/4, size*0.7f);
         drawTree((topX+rootX)/2, (topY+rootY)/2, angle+PI/4, size*0.6f);
      }
   
   }
}