Probabilistic Random Fractal Tree 1
2,701 views · Published 29 July 2011 · 0:21 · Indexed 11 October 2026
Channel: Paul Nathan · 2011 · Education
Example output of some VB and DirectX code I recently wrote to generate and fly around 3D fractal trees. A random number generator is used to determine whether a node branches twice or three times. The branch angles are also generated by bounded random numbers to simulate natural variation. The recursion is up to level 10 in the present example. The branches are represented by simple tapered cylinders that join at their ends. The colour cycling involves travelling waves of R, G and B with respect to the branch recursion level each with different relative phases. The colours are interpolated across the branches too. Such a structure resembles the lung and kidney vascular system (c.f. kidney cast) as well as any other dendritic interconnected topology. A tree can be created either by recursion or by using a stack in a loop. The tree is seeded by pushing a root node into the stack. The loop is then started by popping a node from it and creating child nodes (added to the global dynamic array containing all the nodes) using the rules of branching as specified by you. Each created child node is pushed onto the stack (the order does not affect the final outcome) and the loop is continued until the stack is emptied. This can only happen if a maximum branch level is specified, so when a node is at this maximum level it is not permitted to have child nodes. In order to know how the nodes are linked together, each node structure contains an integer that is given the value of the index of its parent node in the dynamic array that contains the nodes. If desired, a node can also store a dynamic array of indices pointing to its child nodes. This was important in the colouration of the tree where the colours propagate through the branch levels from parent to child.