Remember the Post about Penrose designs? Funny? (Review it, if you didn’t watch it, because it was beautiful). So, today I’m going to show you how you can do some Penrose tilings and maybe one or 2 things about L-Systems (Lindenmayer system).

What a L-System is? Well… without words, these are examples of L-Systems.

With words… really you don’t want words… See wikipedia definition of L-System and come back after “words”.

The basic concept of an L-system is drawing a figure using a rule and repeat this rule in each part of the figure again and again.

For example, we can make the Koch curve in this way describing it as an L-System instead of a Fractal line.

Using common words, the way of doing the Koch curve as a L-System is this. My first draw, my Axiom will be a horizontal line. And my rules says that in each iteartion I will divide my line into 3 lines. The two on the edges will remain, while the one in the middle I use it to make an equilateral triangle. The new lines of the triangle remains, the middle line not.

Now that it is a L-System, there is a very compact way of describing this system using grammars.

Suppose we write **F** for a straight line, **+** to a 60º turn after a straight line, and – to a **–**60º turn after a strigh line. Then we say that for the Koch line we have

**Axiom**: F (We initiate the System drwaing a straight line).

**Constants**: + , – (This are the operation we can apply over our line, basically, we can rotate it for example and then the constant are reffered as angles).

**Rules**: F->F+F–F+F (In each iteration we susbtitute the line F for other 4 straight lines, drwaing the first one along the original, the next one after turning 60º, the third after -120º turn and the last one turning 60º and liying again over the original one).

Very funny… let’s see if we get the idea trying to reproduce the Cesaro-Koch Fractal.

This is the process to do the fractal.

So, what is the grammar?

Axiom: F Rules: F=F+F--F+F; Angle+: 85 Angle-: 85

Basically it’s the same as Koch curve changing the angles!

Ok, let’s go for something a little bit more complex (I’m not expert in L-Systems, actually I´m learning at the same time i try to explain this).

For the next example I’m going to use “The Turtle”. The turtle method consists in viasualizing a small turtle following the rule and having a pencil attached at his back (the pencil can be lifted or down).

Suppose this system:

Which has.

Axiom: F Rules: F=+F+F-F-F+F+F+F-F-F+F; Angle+: 90 Angle-: 90

The turtle method consists in (thank Marylin for the picture) visualizing the rules as:

Cool!

And with the Turtle I can introduce something new. It’s called [ for “push” and ] for “pop”. Basically, this new symbol in the grammar what it does is to remenber a position and to recall it. See in this example how it works.

Can you see the difference? In the bottom example C is related to B, while in the first case C is related to A becase we push [ after A and we pop it again before C. This method works as a LIFO (Last In, First Out) what it means is that if you open several [ at the same time, the first time you close one of them with ] the one which is going to be used is the last one you open.

Ok ok, what else? Well, we can now try using several rules. Using several rules is very easy, you just substitute each rule on to the others until you get everything susbtituted.

For example if you go back to the Koch curve.

Axiom: F Rules: F=F+F--F+F; Angle+: 60 Angle-: 60

You can rewrite it using three rules as this:

Axiom: F Rules: F=SAS; A=+F--F+; S=F; Angle+: 60 Angle-: 60

The reason for using 3 rules is:

F–>SAS–>F+F–F+F–>SAS+SAS–SAS+SAS

Suppouse we use 2 rules as this:

Axiom: F Rules: F=FAF; A=+F--F+; Angle+: 60 Angle-: 60

Then we will have:

F–>FAF–>FAF+F–F+FAF

And you can see the structure changes, because we have to susbstitute rules over what we have and it changes depending on the rules… So it’s a little bit tricky.

I suppose now you want to try some of these things yourself. So it’s InkScape time.

Basically, InkScape it’s superpowered Paint. With some advantages. It’s free and Open Source (you can download it use it and change code as you wish). Can do vector grpahics (when changing the size of things pixels don’t get bigger, it uses vectors to set the positions of things). Can link things and write scripts (if you move things inside a graph, labels and arrows will move to fit the new disposition). Uses a standard kind of files to save your drawings (you can easily import and export files). Can open pdf files and extract parts of them (depending on the pdf you will also be able to edit the pictures and it will recognize different parts on them allowing you to edit them as they were generated by you). It’s available for Windows, Mac and Linux (If you use diferent equips, you can have the same program in all of them). And at last… has an extention to work with L-Systems.

To get this program, just go to their download section and look for the one that fits your system.

Once you have it installed, it’s very easy to generate L-Systems (a few years ago they only way of doing them was to program it yourself, so this is a great tool).

To generate a L-System, inkscape has by default an extension. Extensions>Render>L-System.

A options window will apear allowing you to play with the Axioms and Rules we have discussed before. One extra thing is that Inkscape has two kinds of variables for rules, the ones that draw something and the ones that are only used for displacement. For example, this is the setup for the Koch Island.

Axiom: -F--F--F Rules: F=F+F--F+F; Angle: 60

Hmmm very funny, but get into serious business… Want to impress someone? Try the Dragon curve! (Thanks Penguin Pete for the reference).

Axiom: FX Rules: X=X+YF; Y=FX-Y; Angle: 90

And of course some clasical trees will look very nice. If you randomize step and angle, each iteration will be a small change in the angle and in the longitude of the step. In this case, that will give a more realistic appearance to trees.

Axiom: F Rules: F=F[+F][-F]; Randomize Step (%):20 Angle: 20 Randomize Angle (%):20

That remembered me an applet I did last summer as a gift. You can check my random Forest in Openprocesing (click on canvas an a new one will appear).

Until now, we have deal with systems where there is no overlap, but if you allow it and actually, if you use it, things like this can emerge (Thanks to J C Lawrence).

Axiom: W Rules: W=+++X--F--ZFX+; X=---W++F++YFW-; Y=+ZFX--F--Z+++; Z=-YFW++F++Y---; Angle: 30

Ok, so now we arrive to Penrose P3. (Thanks to the people in the Cornell college for a tutorial like this but maybe more complete and readable than this one).

Axiom: [N]++[N]++[N]++[N]++[N] Rules: M=OA++pA----NA[-OA----MA]++; N=+OA--PA[---MA--NA]+; O=-MA++NA[+++OA++PA]-; P=--OA++++MA[+PA++++NA]--NA; A= Angle:36

For more about Fractals, L-Systems and Strange Attractors, an easy introduction (this time in Spanish):

http://www.dmae.upm.es/cursofractales/

Hope you enjoy it!!

**References:**

L system definition.

http://en.wikipedia.org/wiki/L-system

Koch Snowflake.

http://en.wikipedia.org/wiki/Koch_snowflake

Cesàro Fractal.

http://mathworld.wolfram.com/CesaroFractal.html

Turtle picture.

http://briefinsights.blogspot.co.uk/2011/02/inkscape-l-system-turtle.html

InkScape

http://inkscape.org/index.php?lang=en

Dragon Curve

http://en.wikipedia.org/wiki/Dragon_curve

Penguin Pete. Dragon Curve and several L-Systems in Inkscape.

http://penguinpetes.com/b2evo/index.php?p=694

Some L-System Examples and a Penrose Tiling.

Penrose Tilling.

http://es.wikipedia.org/wiki/Teselaci%C3%B3n_de_Penrose

Cornell College.

http://people.cornellcollege.edu/dsherman/inkscape-fractal.html

Randomize Angle (%):20

## One thought on “L-Systems and Penrose P3 in Inkscape”