An L-System consists of a word over some alphabet and a set of rewrite rules for replacing symbols or subwords by other words.
Words are associative, so we should define In[1]: = Sethttributes[rord, [Plat, OneIdentity\}] these attributes for our data type for words.
Here is a word over the alphabet consisting of the three symbols $\mathrm{m}, 1$, and $\mathrm{r}$.
Our set of rules consists of a single rule for replacing the symbol $\mathrm{m}$ by the given word.
$$
\begin{aligned}
& \text { In }[2]:=\operatorname{gen}=\operatorname{vord}[m, x, r, m, x, r, m] \\
& \text { Out }[2]=\operatorname{vord}[m, r, x, m, r, r, m] \\
& \text { In }[3]:=\operatorname{rules}=\{m \rightarrow \operatorname{gord}[m, 1, m, x, x, m, 1, m]\} \\
& \text { Out }[3]=\{m \rightarrow \operatorname{vord}[m, 1, m, x, r, m, 1, m]\}
\end{aligned}
$$
One application of the rules replaces every occurrence of m by a word; the result is $\operatorname{In}[4]:=\operatorname{gen} 1=\operatorname{gen} /$. rules flattened out, due to the attribute Flat.
$$
\begin{aligned}
& \text { Out }[4]=\operatorname{vord}[m, 1, m, r, r, m, 1, m, r, r, m, 1, m, r \text {, } \\
& \mathrm{r}, \mathrm{m}, 1, \mathrm{~m}, \mathrm{r}, \mathrm{r}, \mathrm{m}, 1, \mathrm{~m}, \mathrm{r}, \mathrm{r}, \mathrm{m}, \mathrm{l}, \mathrm{m}] \\
&
\end{aligned}
$$
We can visualize the resulting words using an idea from Turtle graphics, a simple graphic model used in the language Logo. The turtle sits originally at the origin and faces right. Each letter in our word is interpreted as a command for the turtle to change either its location by moving a certain distance in the current direction, or by turning a certain amount. As the turtle moves, it leaves a visible trail behind.
(Figure Cant Copy)
1. Define a suitable data type for representing the possible states of the turtle.
2. Design a way to specify an interpretation of a word by giving the effect each letter of the alphabet has on the state of the turtle.
3. Program a function for converting a word to a list of points, given an interpretation and the start state of the turtle.
4. Plot the line connecting the points to obtain pictures similar to the ones given here.
5. Optionally remove duplicate points from the line before plotting it. The words will often consist of long sequences of turns between the moves, leading to many occurrences of the same point in lines. For better rendering, only one of a sequence of identical points should be drawn.
Experiment with various generators, rule sets, and interpretations, such as the flowsnake. The alphabet consists of $\{\mathrm{m} 1, \mathrm{~m} 2, \mathrm{r}, 1\}$, the rules are
$$
\begin{aligned}
& \mathrm{m} 1 \rightarrow \text { word }[1, \mathrm{~m} 2, \mathrm{r}, \mathrm{m} 1, \mathrm{~m} 1, \mathrm{r}, \mathrm{r}, \mathrm{m} 1, \mathrm{r}, \mathrm{m} 2,1,1, \mathrm{~m} 2,1, \mathrm{~m} 1] \\
& \mathrm{m} 2 \rightarrow \operatorname{word}[\mathrm{m} 2, \mathrm{r}, \mathrm{m} 1, \mathrm{r}, \mathrm{r}, \mathrm{m} 1,1, \mathrm{~m} 2,1,1, \mathrm{~m} 2, \mathrm{~m} 2,1, \mathrm{~m} 1, \mathrm{r}]
\end{aligned}
$$
Both, $\mathrm{m} 1$ and $\mathrm{m} 2$ are interpreted as moves, and $\mathrm{r}$ and 1 as $60^{\circ}$ turns as before.