Fractal Tree Evolution
A fractal is a never ending pattern that repeats itself at different scales. Fractals are seen everywhere in nature including lightning bolts, blood vessels and hurricane patterns. They often repeat a simple process indefinitely so that it can continuously be zoomed into while seeming to never end. The graph for a fractal pattern is continuous everywhere but nowhere differentiable.
The branching patterns of trees represent a fractal pattern. All branches connect to the trunk of the tree much like a tree data structure. A tree is an abstract data type in which each node may have children and belong to a parent node but all nodes trace back to one root node. An example of a fractal tree structure is a binary fractal tree, which is defined recursively by symmetric branching. There exists a root branch which has two branches and every branch that follows also has two branches. This is a recursive pattern. I used different approaches to implement each fractal tree, weighed the pros and cons to each method. I was able to add features such as color using Canvas.
Simplicity leads to complexity!
The first tree was created via a simple, single class method. It is a binary tree in which every child branch is created at a 60 degree angle and with a length that is a fraction of its parent branch. Note that all the branches on each 'level' of the the same size. The pattern stops when the brench length is less than five pixels. The 'stiffness' of this tree is a result of every branch being at an angle relative to the entire canvas rather than each individual branch. This method of creating a fractal tree was to outline the general approach to creating fractals.
This fractal tree was implemented recursively. The recursive approach allows for much cleaner and readable code. The proper angles for the tree were achieved by using the Canvas' translate and rotate method. The function creates the right and left branch recursively and stops when a minimum length has been reached. This approach creates a much nicer fractal tree.
This fractal tree was created using a Lindenmayer-System (L-System). An L-System is essentially a blueprint that the fuction will read and generate the appropriate response to. While reading the initial blueprint, the L-System will also subsitute each character based on the set rules defined. For example, this L-System begins with a single 'F' character. The rule is for every 'F' character seen, the next blueprint should have 'F+[+F-F-F]-[-F+F+F]' in its place. This will cause the string and tree to grow. L-Systems were introduced by Aristid Lindenmayer, a Hungarian biologist and botanist, to model the growth behaviour of plants. Therefore, using a L-System was another great method for generating a fractal tree. This L-System interprets the following characters: "F", "-", "+", "[" and "]". The "F" character signals to create a branch, the "+" rotates the canvas by 20 degrees, the "-" character rotates the canvas by -20 degrees, the "[" symbol saves the current canvas state while the "]" symbol restores the previous canvas state.
This fractal tree is created with a combination of two previous methods. Each right and left branch is being generated recursively but each branch is its own class object. In comparison to the previous recursive approach, I now have control of each branch. Now we are able to see the branches grow layer by layer and even add some leaves to it!