Elm – fun with L-System (Part 7)

Series:

  1. Algae
  2. Pythago­ras Tree
  3. Can­tor Dust
  4. Koch Curve
  5. Sier­pin­ski Tri­an­gle
  6. Drag­on Curve
  7. Frac­tal Plant (this)

Last time out we imple­mented the Drag­on Curve exam­ple from the L-Sys­tem wikipedia page. Now, we’re final­ly at the end of our jour­ney, let’s see how we can imple­ment the Frac­tal Plant exam­ple in Elm.

 

Example 7 : Fractal Plant

Let’s start by defin­ing our L-Sys­tem:

image

What’s inter­est­ing about the Frac­tal Plant is that it com­bines ele­ments from Pythago­ras Tree (the use of a stack) and oth­er L-Sys­tems we looked at recent­ly.

image

 

Here’s how it looks, by gen 7 the plant looks pret­ty good!

fractal_plant

 

In fact, with the imple­men­ta­tion we end­ed up with, we can use it to sup­port any num­ber of L-Sys­tems so long:

  • F’ is the only sym­bol that means “draw for­ward”
  • we can pro­gram­mat­i­cal­ly change the angle for ‘–’ and ‘+’ (easy!)

with that, let’s take a cou­ple of the exam­ples from LSys­tem­Bot’s tweets and see them in action!

 

Example 7.1

image

 

l-system-bot-01

 

Example 7.2

image

l-system-bot-02

 

Example 7.3

image

l-system-bot-03

 

So that’s it guys, hope you’ve enjoyed this series! Please let me know via the com­ments if you like to see more mini-series like this one.

 

Live Demo (here)

Use LEFT and RIGHT arrow keys to evolve/devolve the L-Sys­tem.

Source Code (here)

 

 

Links