Let’s start with the basics, if we take the definition from the well-known and beloved Wikipedia, then **the L-system** (or** Lindenmeier system**) is a parallel rewriting system and a type of formal grammar.

In simple terms, the **L-system **consists of an alphabet of characters that can be used to create strings, a set of generating rules that specify substitution rules for each character, the initial string (* “axioms”*), with which the construction begins, and the mechanism for translating the formed string into geometric structures. The simplest example** of an L-system** is the tree construction problem.

__Input data:__

** String **(

** Variables **(

** Rule** (

- A – > AB
- B – > AC
- C – > A

These transformations are obtained:

Generation | Condition |
---|---|

1 | A B |

2 | AB AC |

3 | AB AC AB A |

4 | AB AC AB A AB AC AB |

5 | AB AC AB A AB AC AB AB AC AB A AB AC |

6 | etc… |

The main direction in which** L-systems**are used is modeling the growth processes of both living organisms and non-living objects *(crystals, mollusk shells or honeycombs)*.

Example:

To simulate such processes, we will use a programming language such as Python, it has a built-in library **“turtle”**.

__So, let’s get started:__

- Here we import
**the Turtle library**into our project:`import turtle`

- Next, we connect all the necessary configurations for our
:*turtle*`turtle.hideturtle()`

`turtle.tracer(1)`

`turtle.penup()`

`turtle.setposition(-300,340)`

`turtle.pendown()`

`turtle.pensize(1)`

- Next, we specify the value of the axiom itself and the associated parameters necessary for specifying the sequence:
`axiom = "F+F+F+F"`

`tempAx = ""`

`itr = 3`

*(**itr –**values of loop iterations, we will need it in the next step when writing our program)* - In this cycle, where we just need
**the ITR-variable**, we are engaged in processing and “growing” the genome of our fractal/plant directly:`for k in range(itr):`

`for ch in axiom:`

`if ch == "+":`

`tempAx = tempAx + "+"`

`elif ch == "-":`

`tempAx = tempAx + "-"`

`elif ch == "F": #F`

`tempAx = tempAx + "F+F-f-F+F"`

`else:`

`tempAx = tempAx + "f"`

`axiom = tempAx`

`tempAx = " "`

`print(axiom)`

If we run through the loop, we will immediately see a filter for**the “+”symbol in the first condition**:`if ch == "+":`

`tempAx = tempAx + "+"`

Here we look for the “+” sign in the axiom (the original line) and when it appears, we add**the “+” symbol**to the next line. The same thing happens with**the “-”**and**“f ” characters**, we just add**the “-”**and**“f” characters to the next line**, respectively. But when the symbol**“F” appears in our axiom**, we will act a little differently and add the sequence of characters**“F + F – f – F + F”**to the next line , to increase the length of each subsequent line. This action, in principle, is not essential, but for the speed of generating**the ” genome”**I decided to do just that. At the end, we make sure to equate the axiom with our genome and reset it:`axiom = tempAx`

`tempAx = " "`

The result*(the value of the axioms)*: - Well, it seems that everything is clear on genome generation, let’s start directly with visualization. To do this, we need a simple loop that will translate the symbols found in the genome into the movements of the turtle:
`for ch in axiom:`

`if ch == "+":`

`turtle.right(45)`

`turtle.forward(10)`

`turtle.right(45)`

`elif ch == "-":`

`turtle.left(45)`

`turtle.forward(10)`

`turtle.left(45)`

`else:`

`turtle.forward(20)`

You can immediately see that by analogy with the previous paragraph, we detect the characters**“+”,” -“, “F”**and**” f”**. Only now at the moment when we encounter**the “+”symbol**:`if ch == "+":`

`turtle.right(45)`

`turtle.forward(10)`

`turtle.right(45)`

We turn first to the right,**45 degrees**, then drive a distance of**10**, and then we turn again to the right,**45 degrees**. When do we encounter**the “-“symbol?**:`elif ch == "-":`

`turtle.left(45)`

`turtle.forward(10)`

`turtle.left(45)`

We do all the same actions as with**the ” + ” symbol**, only this time we turn not to the right, but to the left. But if we encounter the characters**“F”**or**“f”**, then we will simply drive forward**20 pixels**:`else:`

`turtle.forward(20)`

As a result, we get such*a fractal-a snowflake*: - If we want to colorize our
*fractal snowflake*, then we will need to add lines before the cycle from the previous paragraph:`turtle.fillcolor("#99BBFF")`

`turtle.begin_fill()`

Whereis the color encoding*#99BBFF**(RGB: 153, 187, 255)*, andis the start of filling in the color. And at the end, after the loop, add the lines:*begin_fill()*`turtle.end_fill()`

`turtle.update()`

`turtle.done()`

Аозначает конец заполнения. Далее мы обновляем и выключаем нашу*end_fill()**“черепашку”*. И на выходе мы получаем вот такой*фрактал-снежинку*:

In the end, I also want to add that I really enjoyed working and writing on this topic, perhaps in the future, I will write a number of articles on the topic of “L-systems”, but in the meantime, I want to present you the results of my poking creativity: