Done using processing.
In this example, the light source is coming from the right. Hence the tree branches out towards the right. They are created from adding branches from previous branches, with the trunk being the first “branch”.
At the end of each branch, there is a 60% chance for the next branch to grow to the right, and 20% to the left and another 20% to the middle. This is done by generating a random number between 0 – 1 and if statements.
A route (from the trunk to the first branch, to the second… to the last) is completed first before the next route starts. Each route is entirely probabilistic.
For future exploration:
Currently, the implementation of a “light source” is only through defining the probabilities of growing right, left and center. I would like to be able to define a light source. The probability of growing towards the light source will depend on the distance the previous branch is from the light source. Closer = greater probability of growing towards it.
Also, currently, I am using a predefined angle of 30 deg when it branches out. I’d like to use the position of the light source as reference for the direction the branch should grow towards