Fractals and L- Systems Sanyam Gupta January 26, 2018 1 Lindenmayer systems Have you ever wondered, how to formulate a mathematical equation for the plant in your verandah or garden? The nature produces amazingly complex systems from simple starting points. Aristid Lindenmayer, a Hungarian theoretical biologist and botanist at the University of Utrecht. He developed the axiomatic thinking for the development of the biological systems. Lindenmayer systems (or L-systems) are the mathematical formalism for this axiomatic thinking, provided by Aristid Lindenmayer. In L-systems, complex structure develop through string rewriting. A string of letters is transformed into a new string of letters using simple rules called productions. The process of string transformation is repeated indefinitely. 1.1 Rewriting systems L-systems repeatedly rewrite a string. In general, rewriting is a technique for defining complex objects by successively replacing parts of a simple initial object (aka Axiom) using a set of rewriting rules or productions. The classic example of a graphical object defined in terms of rewriting rules is the snowflake curve, proposed in 1905 by von Koch. Mandelbrot restates this construction as follows: One begin with two shapes, an axiom and a generator (productions). The latter is an oriented broken line made up of N equal sides of length r. Thus each stage of the construction begins with a broken line and consists in replacing each straight interval with a copy of the generator, reduced and displayed so as to have the same end points as those of the interval being replaced. Illustration: F = move forward by a certain distance, = turn right by a certain angle δ, + = turn left by a certain angle δ. 1
Let, axiom= F ++F ++F, this corresponds to a equilateral triangle if δ = 60 (figure 2 for n = 0), and let, generator = F F + +F F, this corresponds to figure 1. So, whenever you see F in the axiom you replace it with the generator, and the resultant would be our new axiom. Therefore, old axiom becomes:(f F + +F F ) + +(F F + +F F ) + +(F F + +F F ) and this is our new Gen- Figure 1: erator axiom. We say, our first iteration has happened. This new axiom corresponds to figure 2 when iteration (n = 1). Further if we iterate this new axiom one more time i.e. n = 2 then we will get a rather clumsy axiom and a good approximation to the Koch Snow flake, for n = 3 this good approximation becomes a close approximation to the Koch Snow flake. Similarly if we iterate it infinitely many times (practically impossible, theoretically possible) then we can construct pure Koch Snow flake. Figure 2: Koch Snow flake 1.2 Turtle interpretation of strings The basic idea of turtle interpretation is very simple. A state of turtle is defined as a triplet (x, y, α), where Cartesian coordinates (x, y) represent the turtles position, and the angle α, called heading, is interpreted as the direction in which the turtle is facing. Given the step size d and the angle increment δ, the turtle can respond to the commands represented by the following symbols F, f, +,. Provided the value of d and δ. F : Move forward a step of length d in the direction of the heading. 2
f: Move forward a step of length d in the direction of the heading, without drawing a line. +: Turn left by an angle δ. : Turn right by an angle δ. For example, figure 3 presents approximation of Quadratic Koch Island as given in Mandelbrot s book. This figure was obtained by interpreting strings generated by the following L-system: Axiom:F F F F Production (generator):f F F + F + F F F F + F This image corresponds to the strings obtained in derivations of length d = 2(i.e. two pixels) and δ = 90. This example reveals a close relationship between constructions and L systems. Below are some examples along with the axiom, productions, number of iterations (n) and δ. Go and check those example on the online 1 Python Program. Quadratic Koch Island Axiom: F F F F, Generator: F F +F F F F F F +F +F F F F +F +F F +F F F, n = 2, δ = 90 Figure 3: Quadratic Koch Island Quadratic modification of the snowflake curve Axiom: F, Generator: F F +F F F +F, n = 4, δ = 90 Rings F F F F F + F, n = 4, δ = 90 Box F F F F F, n = 4, δ = 90 Koch Carpet F + F F F F, n = 3, δ = 90 1 https://trinket.io/python/8fe1caf5bd?outputonly=true&runoption=run 3
1.3 Branching structures and Bracketed L-systems According to rules presented so far, turtle interprets a character string as a sequence of line segments. However the plant kingdom is dominated by branching structures; thus a mathematical description of tree- like shapes and the methods for generating them are needed for modeling purposes. Two new symbols are introduced to delimit a branch. They are interpreted by the turtle as follows: [ : Push the current state of the turtle onto a pushdown stack. The information saved on the stack contains the turtles position and orientation, and possibly other attributes such as the color and width of lines being drawn. ] : Pop a state from the stack and make it the current state of the turtle. No line is drawn, although in general the position of the turtle changes. As an example of Bracketed L- systems and its turtle interpretation, obtained in the derivation of n = 3 and length d = 3. This figure was obtained by the interpretation of strings of the following L-systems. Axiom : F, Generator: F F [ F F ] + [F F F ] F F [ F F ] and δ = 20. Some more examples: 1. n = 4,δ = 25.7,Axiom: F, Generator: F F [+F ]F [ F ]F 2. n = 4,δ = 20,Axiom: F, Generator: F F [+F ]F [ F ][F ] Figure 4: Plant like structure 3. n = 4,δ = 22.5,Axiom: F, Generator: F F F [ F + F + F ] + [+F F F ] 2 Evolving Plants As you have seen in the previous examples, the tree thus far evolved only included one variable (i.e.f) terminal symbol. But the nature is more complex than these given examples, for this many more variable terminal symbols are introduced further, doing the same task that (F ) is doing. Introduction of more variables increases the size of the search space since there are a greater number of potential L-systems that can be produced from this type of grammar. Here only one new variable terminal symbol is introduced for illustrating that we can achive more complex 4 Figure 5: More complex Plant
systems by introducing more variable terminal symblols. Let s look at an example figure 5. Variables:XF,n = 5,δ = 30,Axiom: X, Generator(F ): F F F, Generator(X): X F [+X][ X]F X Some TIY 1 examples: Variables:XF,n = 5,δ = 22.5,Axiom: X, Generator(F ): F F F, Generator(X): X F [[X] + X] + F [+F X] X Variables:F,n = 6,δ = 30,Axiom: F, Generator(F ): F F [ F ][F ][+F ] 3 Fractals and L-systems Fractal curves can be represented by L-systems, as we have seen previous examples of Koch Curves. They are all fractals and are represented by the L-system grammar. Let s see an example of Sierpinski triangle: Variables:XF,n = 5,δ = 120,Axiom: F, Generator(F ): F X F X, Generator(X): X F + X + F (TIY). Another example: Variables:F,n = 5,δ = 45,Axiom: F + +F + +F + +F, Generator(F ): F F + F F + + + F + +F F F + + + F + +F F (TIY). Variables:F,n = 4,δ = 90,Axiom: F + F + F + F, Generator(F ): F F + F F F F F + F (TIY). Since, due to the machine restrictions the above examples cannot be iterated infinitely many times, if these examples are iterated infinitely many times then they will give rise to the Fractals i.e. self similar patterns, because fractals are the limiting case when n. But these examples give an beautiful algorithm to create fractals.there are many more patterns, you can create your own pattern, and try it on the above given Python program. 1 Try it yourself on Python Program at https://trinket.io/python/8fe1caf5bd? outputonly=true&runoption=run 5