The Environmentally Sensitive Pruning L-System

The main L-System that was used to create the topiary, was taken almost in full from the 'Synthetic Topiary' paper.

The L-System is defined as follows:

/* d is a constant designating the forward distance. */

w:       F(d)A(1)?P(*, *, *);
p1:     A(k) > ?P(x, y, z) : inside(x,y,z) -> /(90) [+(32)F(d)A(k+1)?P(*,*,*)]-(20)F(d)A(k+1):min(1,(2*k+1)/k^2);
p2:     A(k) > ?P(x,y,z) : inside(x,y,z) -> /(90)B(k+1,k+1)-(20)F(d)A(k+1):max(0,1-(2*k+1)/k^2);
p3:     A(k) > ?P(x,y,z) : outside(x,y,z)->T()%;
p4:     F(x) > T()->S();
p5:     F(x) > S()->S()F(d);
p6:     S()-> /* epsilon */;
p7:     B(m,n)>S()->[+(32)F(d)A(a*m+b*n+c)?P(*,*,*)];
p8:     B(m,n)>F(x) -> B(m+1, n);
p9:     T()-> /* epsilon */;

/* Ignore all turtle interacting modules */
#ignore /, -, +;

According to axiom w, development begins with a single internode F, supporting apex A(1), and query module ?P(*, *, *). Productions p1 describes the creation of two new branches while production p2 describes the production of a branch segment and a dormant bud B. Probabilities of these events are equal to p=min(1, (2*k+1)/(k^2) ), and q=1-p, respectively. Since k is the relative age of the apex A, the probabilities formulas are defined in such a way that young apex p1 has a greater probability of being selected thus exhibiting exponential growth. When apex becomes older, the probability of p1 decreases while the probability of p2 increases, and eventually p2's probability becomes large enough and the plant no longer grows exponentially.
Note that p1 and p2 are only valid if the turtle is currently inside the bounding object, thus making sure that the plant will not grow further if it is outside the bounding object.

When a branch extends beyond the bounding object, production p3 removes apex A, cuts off the query module ?P(x,y,z) and generates the pruning signal T(). In presence of this signal, production p4 removes the last internode (F()) of the branch that extends beyond the bounding object, and creates bud-activating signal S(). Productions p5, p6 propagate this signal basipetally (downwards to the root of the tree), until it reaches a dormant bud B(), production p7 induces this bud to initiate a lateral branch consisting of internode F() and an apex A() followed by query module ?P(*, *, *). According to production p1 this branch develops in the same manner as the main axis. When its apex extends beyond the bounding object it is removed by production p3 and signal S is generated again. This process may continue until all dormant buds have been activated.

Growing A Tree Inside A Cube - An Example
Below are the first 16 generations (0-15).

... and a llittle later :

Generation 30

Click here to view the animation of the above first 16 frames.