The loop for each branch is as follows:
{
Create a branch
loop for each sub-branch
{
create a sub-branch
loop for each pine needle
{
create a sub-sub-branch
}
}
}
Almost any tree model will have such a structure. The trick is to know how to position the sub-branches on each branch and how many to create. The positioning is comparatively simple if the branching structure is also used to control the transformation hierarchy: then the branches only need to be rotated about their origin and then translated along the branch.
For position i


where M is the maximum length for the segment,
t is the time,
k is the growth initiation rate, and
d is the growth rate.
The position of the segment a is L(a) which is given by

Given an index value


Where m defines the maximum rate of change of position with respect to the branch number,
d defines the time interval over which growth rate decays to zero, and
k defines the rate at which the new growth initiator moves with respect to position index.

The needle density was increased until the computer ran out of paging disk. Fir trees are pathologically complicated. Try using fewer branches and no needles. Try placing fruit on the branches, or create candles for a Christmas tree. Try adapting the model for curved branches, such as on an apple tree.