Browse files

began implementation of tree creation scenes

  • Loading branch information...
GandhiGames committed Dec 20, 2016
1 parent e17678b commit 94118e2ae3a7e6615938967c50a611317aecb620
Showing 2,201 changed files with 44,931 additions and 6,534 deletions.
@@ -0,0 +1,80 @@
Fractal Trees
Gandhi Games
A fractal is a pattern that repeats at different scales. We call these shapes ?self-similar?. While they have only been known as fractals since the 1970s, they were first described by Leonardo da Vinci in the 15th century.
Nature is full of fractal patterns including trees, lightning bolts, and river networks. Spirals such as hurricanes and even galaxies are also considered fractals.
Fractal Trees
A tree is a type of an approximately self-similar fractal, where smaller parts of the tree look generally similar to the larger tree. A tree is formed by repeating a simple process, which is also the basic principle that is used when generating fractals programmatically. While the fractals generated can appear complex and detailed, they are created by repeating a number of simple steps.
The algorithm for growing a tree is roughly like so:
1. The tree sprouts.
2. The sprout eventually splits into branches.
3. These branches themselves split into further branches.
At each step of this process it is as if two new smaller trees emerge. These smaller trees can be conceptualized as the trunks of a new generation of trees. This repetition of branching that forms the tree is also the cause for trees approximate self-similarity. In nature this process eventually stops and the end products are no longer fractals.
There are a number of different methods to generate fractal trees programmatically, including the Lindenmayer system and Space Colonization.
Lindenmayer Systems
Computers are important tools in the study of the structural patterns in natural and computer generated organisms. Lindenmayer systems, shortened to L-systems, (introduced in 1968) were one of the first occurrences of the use of computational power to study these patterns.
An L-system creates sets of strings based on a rule set. The system starts with an Axiom (or seed), and then rules are recursively applied to the string to produce an output string or sentence. The output sentence can then be fed into other systems to produce graphical output.
For example:
Axiom: AB
Rules: A -> AB, B -> A
Gen 1: AB (Initial Axiom)
Gen 2: ABA (A converted into AB and B into A)
Gen 3: ABAAB
Generation one starts with the axiom. In subsequent generations any instance of ?A? is replaced with ?AB? and ?B? with ?A?.
By giving each character a specific action and implementing turtle graphics ( we can generate trees.
The system uses a version of the d0L-system Grammar Description Language. This language provides rules that can be applied to each character generated by the L-System.
C0, C1? CnChange all subsequent drawn lines to colour n.
FMove forward in current direction and draw line.
GMove forward in current direction without drawing a line.
-Rotate direction left by n degrees.
+Rotate direction right by n degrees.
[Store current state.
]Restore saved state.
!Reverses the meaning of left and right.
|Turn 180 degrees.
Using these actions and a specific Axiom and rule set, you can create the tree shown in the image below.
Axiom: FX
Rules: F -> C0FF-[C1-F+F]+[C2+F-F], X -> C0FF+[C1+F]+[C3-F]
Generations: 5
Each generation produces a tree more complex than the last.
Further example rule sets used can be found online, for example:
Space Colonization
Space Colonization is another method of generating trees. You start by defining the leaves. These leaves act as a target for branches to grow towards. They can be spawned randomly or hand placed. The tree?s trunk is then grown until it is within a specified distance of a leaf. From this point, the tree will grow towards the leaves.
For each branch end an attraction vector towards leaves within distance is added. This vector is then used to spawn new branches and the process continues. Whenever a segment end is too close to a leaf, the leaf is removed. As the branches grow towards the leaves most (if not all) leaves will be removed at the end of the tree generation process.
Using this process, branches naturally avoid each other; each branch appears to have developed as the result of seeking sunlight. This same method can also be used to generate the roots of the tree.
You can create vastly different trees by adjusting the minimum and maximum distance seek distance to leaves, and the width of branches.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,111 @@
Fractal Trees with Springs
Gandhi Games
How it Works
This section contains a brief summary of how the tree types are generated. For more information, see the ?Fractal Tree Information? documentation.
Branching Tree
The branching tree has a simple generation process, for each generation:
1. Create a branch
2. Split into two branches based on angle
The L-System starts with an Axiom (seed), for example: ?F?; and a set of production rules, for example ?F=F[+F-]X? and ?X=-FF?. Using these parts, a sentence is generated over a number of generations by applying the rules to the axiom and each successive sentence.
For example:
Gen 1 = F (initial Axiom)
Gen 2 = F[+F-]X (F changed into ?F[+F-]X?)
Gen 3 = F[+F-]X[+F[+F-]X-]-FF (any subsequent F?s changed into ?F[+F-]X? and X into -FF)
This process will continue for a number of generations until a final sentence is produced. This sentence is then used to generate a tree by looping through each character of the sentence and applying the following rules:
C0, C1? CnChange all subsequent drawn lines to colour n.
FMove forward in current direction and draw line.
GMove forward in current direction without drawing a line.
-Rotate direction left by n degrees.
+Rotate direction right by n degrees.
[Store current state.
]Restore saved state.
!Reverses the meaning of left and right.
|Turn 180 degrees.
Space Colonization
Place a number of ?leaves in the scene?. These leaves should all be the child of a single GameObject and each leaf should have the ColonizationLeaf script attached. You can have the leaves generated for you by attaching ColonizationLeafGenerator to a GameObject in the scene. This will generate a number of leaves within a circle radius.
With the leaves placed the tree can grow. It does this by looping through each leaf:
1. If any leaves are within a minimum and maximum distance, then the next branch direction is rotated towards that leaf (if a number of leaves are found then an aggregate direction is calculated).
2. Any leaves that are below the minimum distance are removed from the simulation.
These steps are performed until no suitable leaves are found.
How to Generate Trees
1. Add either the StationaryTreeBuilder or MovingTreeBuilder script to a GameObject (depending on whether you will be applying a force to the tree or not). Moving trees are computationally expensive and should only be used when necessary.
2. Add either the ?Stationary Branch? prefab or the ?Moving Branch? prefab (StationaryTreeBuilder must have the Stationary Branch prefab and the MovingBranchBuilder must have the Moving Branch prefab).
3. Choose your tree type.
4. Adjust the tree settings.
If you are creating a Space Colonization tree, then you will also need to setup the ?Leaf Parent?. You can create leaves either manually or by adding a ColonizationLeafGenerator script to a GameObject (check the Tree Demo for an example setup).
How to Apply Forces
When you have created a moving tree you can apply forces by calling the methods in MovingTreeBuilder:
* ApplyDirectedForce: applies a uniform force in the direction specified.
* ApplyPushForce: applies an explosive force that radiates from the position specified. Force is applied relative to the distance from the point.
* ApplyPullForce: applies an implosive force that radiates from the position specified. Force is applied relative to the distance from the point.
See DemoForceController script for an example of applying forces.
Inspector Variables
Select tree type in inspector to get tree specific options. The variables are outlined below.
Branching Tree
Branch ColourThe colour of the tree. The branching tree can only be one colour.
GenerationsThe number of iterations to grow. Larger numbers result in bigger trees.
Initial LengthThe length of the initial tree trunk.
Length Multiplier On New Generation The length of the branch is multiplied by the number on each successive generation.
Enter a number less than 1 to reduce the size each generation.
AngleThe angle used when splitting a branch.
Branch WidthThe width of all branches on the tree.
Auto WidthAdjust the width based on the colour index.
Mass Based on Width (moving trees only)Adjust the mass based on the width of a branch.
Branch Initial WidthThe initial width of the tree. This will be the width of all branches if auto width is false.
GenerationsThe number of iterations to process. Larger numbers result in larger sentences. The processing time grows exponentially.
AxiomThe initial seed.
L-Tree RulesThe rules to apply to the axiom and each successive sentence.
Branch LengthThe length of the branches.
AngleThe angle applied on branching.
L-Tree ColourThe colours. Only the first colour will be used if the rule set does not include colour indices.
Space Colonization
Branch ColourThe colour of the branches.
Branch Initial LengthThe length of the branches until a leaf is found.
Branch WidthThe width of the branches.
Min Distance to LeafThe minimum distance to nearby leaves. When a branch gets within this distance to a branch it is removed.
Max Distance to LeafLeaves further than this distance are ignored by the tree.
@@ -1,41 +1,2 @@
var menudata={children:[
{text:'Main Page',url:'index.html'},
{text:'Class List',url:'annotated.html'},
{text:'Class Index',url:'classes.html'},
{text:'Class Hierarchy',url:'hierarchy.html'},
{text:'Class Members',url:'functions.html',children:[
{text:'Main Page',url:'index.html'}]}
@@ -1,27 +1,11 @@
[ "Fractal Spring Tree Generator", "index.html", [
[ "Packages", null, [
[ "Packages", "namespaces.html", "namespaces" ]
] ],
[ "Classes", "annotated.html", [
[ "Class List", "annotated.html", "annotated_dup" ],
[ "Class Index", "classes.html", null ],
[ "Class Hierarchy", "hierarchy.html", "hierarchy" ],
[ "Class Members", "functions.html", [
[ "All", "functions.html", null ],
[ "Functions", "functions_func.html", null ],
[ "Variables", "functions_vars.html", null ],
[ "Enumerations", "functions_enum.html", null ],
[ "Properties", "functions_prop.html", null ]
] ]
] ]
] ]
[ "Fractal Spring Tree Generator", "index.html", ]
var SYNCONMSG = 'click to disable panel synchronisation';
Oops, something went wrong.

0 comments on commit 94118e2

Please sign in to comment.