Create a kind of branching device. It starts in the middle of the screen and then grows in a random direction. The length each branch is fixed and the direction in each junction is random.


  ----  Bjork Bo Christensen  ----
  This script tries to mimic the growth of a tree. So far there is only one branch.
  I have tried to mimic some kind of 3D effect, but it is really only 2D.
  I haven’t configured the function that controls the script so that I understand where it has just been,
    which mean that the output is fare from tree-looking.
  I also need to put in boundaries to keep the tree within in the screen.
The different parts.
1. First declare the variables. All variables declared before the first function is top-level variables.
They can be used within all functions.
2. The Setup function. Contains small stuff about the size of the screen, the background color and stuff like that.
3. The Draw function. The place where the tree-function is executed over and over again.
4. The tree function. Here Is where it all happens. The tree function needs 4 inputs.
Every time this function is executed, exactly one branch is drawn.
//Declaring top-level variables
float ang = 270; // The angle on the next branch
int lenght = 15; // The lenght of each branch
int level = 3; // Number of levels on the tree
int screen_X = 800; // Screen resolution
int screen_Y = 600; // Screen resolution
int tree_coord_X = screen_X / 2;
int tree_coord_Y = screen_Y / 2;
void setup() {
  background (0);
void draw() {
ang = int(random(360));
tree(level,lenght,tree_coord_X,tree_coord_Y); // Call the function that draws the tree
void tree(int tree_level, int tree_lenght, int trans_X, int trans_Y) {
  // need a mechanism for turning the origon
  float[] Coord_X = new float[1000];
  float[] Coord_Y = new float[1000];
  translate(trans_X,trans_Y); // Move the origin
  for(int i=0; i<tree_lenght; i++) // Convert polar degrees to Cartesian
    Coord_X[i] =  i * cos(ang);
    Coord_Y[i] = i * sin(ang);
    //  This is the part that actually draws the tree.
    // The idea is to draw three circles, in three different colors to give it a nice (fake) 3D effect.
    ellipseMode(CENTER); // The widest circle. Gives the feeling of geometry
    fill(30); // Color dark (the color range from (0=black to 225=white)
    ellipseMode(CENTER); // The mid circle. Gives the feeling  of ambient light
    fill(180); // Medium
    ellipseMode(CENTER); // The smallest circle. Gives the feeling of high light
    fill(225); // brightest color possible
tree_coord_X = tree_coord_X + int(Coord_X[tree_lenght-1]);
tree_coord_Y = tree_coord_Y + int(Coord_Y[tree_lenght-1]);