Detailed explanation of how the Plant 1f curve is drawn

The first program - Plant 1f - is made using a "turtle" that advances in the way stipulated by its chain of instructions. In each iteration, a set of substitution rules is applied to modify the chain. That is what is called a "formal grammar to generate chains of characters".

The program uses a "turtle" that advances in the way stipulated in a chain of instructions. In each iteration, a set of substitution rules is applied that modifies the chain. This set of rules is a formal grammar that generates chains of characters (a system of Lindenmayer - or "L-system"). The rules for Plant 1f are the following:

0 -» 1 [+0] 1 [-0] 0
1-» 11
[-» [
]-» ]

The character 0 corresponds to drawing a circle ("a flower") at the current point (anternating blue and yellow color). It is from each circle that later the branches grow, by the application of the first rule.
The
character 1 corresponds to a step ahead, in a direction imposed by an angle teta, to one point at a distance dist. + and - correspond to adding or subtracting angle teta by the selected angle (initialy set to 45º). Rule 1-» 11 duplicates the length of the lines in each iteration. (To keep the figures always of the same size, dist is divided by 2 in each iteration.

[ corresponds to saving the current values of teta, x and y to be able to come back to the same position when the corresponding ] is executed . Notice that various characters [ can occur before one character ] . And thus there is a nesting of these commands whose level is the same as the rule application iteration number. As only 10 iterations are used, the matrices where the values are kept during execution only need to have the capacity to store 10 elements. Notice that, when the sequence is [ +0 ] or [ - 0 ] , the position kept in the command [ is immediately restored after drawing the circle ].

Initially, the chain has only one 0 character. That corresponds to the initial circle. Then, in iteration 1, the 0 is substituted by 1 [+0] 1 [- 0] 0. This sequence corresponds to drawing a line ( 1 ), to draw a circle ( [ +0 ]) , to draw a line ( 1 ), to draw a circle ( [ - 0 ] ) and one another final circle (in the same small farm that the previous one).

In iteration 2, the chain 1 [+0] 1 [- 0] 0 is replaced by 11 [+ 1 [+0] 1 [- 0] 0 ] 11 [ - 1 [+0] 1 [- 0] 0 ] 1 [+0] 1 [- 0] 0 . This sequence corresponds to drawing a double line (11[), add 45º to teta (+), draw a copy of the branch of the first iteration (1 [+0] 1 [- 0] 0), come back to the end point of the double line (]), draw a double line (11[), subtract 45º to teta (-), draw a copy of the branch of the first iteration (1 [+0] 1 [- 0] 0), come back to the end point of the double line (]), draw a copy of the branch of the first iteration (1 [+0] 1 [- 0] 0).

Notice that the length of the chain of instructions grows very quickly: 1, 11, 43, 143, 451, 1391, 4243, 12863, 38851, 117071, 352243...