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 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. [ 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). |