Press no key to discontinue...

Inkscape Tutorial - L-System Fractals

Date/Time Permalink: 04/12/11 12:17:08 pm
Category: Graphics Tutorials

I've been playing around with the latest version of Inkscape (that's 0.47 on my 'buntu) and noticed that, along with the massive amount of new features it's gained, several old fractal-type functions have been consolidated into just the L-system. So my old Inkscape trees tutorial is outdated. But along with that, the L-System dialog just doesn't seem to be documented in manuals, but various bloggers have discovered it and played with it, like this cool blog post with a great guide illustration, this blog with several posts dealing with L-System, and a few others you'll find when you Google "Inkscape L-System."

So let's dive in! The L-System dialog (extensions-> render-> L-system) is actually a little language all to itself, similar to Logo turtle-drawing graphics. If you click the 'help' tab in the tutorial, there's a few clues there. It's actually an implementation of the Lindenmayer System from mathematics (via biology!).

From what I've observed, 'Axiom' gives the command. It's actually kind of confusing, because you can enter the formula directly in the axiom box, name the formula in the axiom box and enter it in the 'Rules' box, etc. 'Rules' gives, ah, the command. Or the formula(s). 'Order' is how many times we'll repeat the Axiom (?) or Formula. 'Step length' is how many pixels to travel, 'left angle' and 'right angle' is the angle to turn in degrees, and the two randomizers cause the parameters to vary slightly.

Canonically, it looks like you enter functions into the 'rules' box and execute them with the 'axiom' box.

Now, a fuller breakdown of the "language" as far as I've discovered:

Letters A-thru-L: It says you use G-L for moving and A-F for drawing, but try defining 'G=AA..' and watch G draw when you call it anyway. The better description seems to be: Letters A-F draw and letters G-L move without drawing, unless you use them for variable names too. Additionally, the letters M-Z seem to be available for variable names anyway.

(+ , - , |) - Turns left, right, and 180-degrees. The left and right are the ones affected by your degrees entry in the 'left angle' / 'right angle' boxes.

([ , ]) - The square brackets set a point marker ([) and return to it (]). They seem to work recursively, so you can set multiple points ( [A[A[A ) and then return to the third-most-recent point by calling the right square bracket three times in a row ( ]]]A ). Only a Lisp-head would love this.

( = ) - The equals sign assigns a function. (F=A--B)

( ; ) - The semicolon ends a function assignment. Useful only if you're going to declare multiple functions ( X=AA-A; Y=A+AA; )

So, some little rule sets I've stumbled on:

L-System fractal formula

Rule: F=F+F+;
Angle: 90

Makes a Levy C curve.

L-System fractal formula

Rule: F=F+FF+F+;
Angle: 90

Looks like a lighter, airier version of Levy C.

L-System fractal formula

Rule: F=FF-F-;
Angle: 90

Gives a really chaotic tiling.

L-System fractal formula

Just for the sake of showing what you can do with this stuff, here's one where I made an order-7 version of that last one, set the path to be width 5.0, converted stroke-to-path with Ctrl-Alt-C, removed fill and set path back to 1.0 - the resulting outline is on the left. On the right, same outline copied a couple times with some filter effects. Now you see where this is going?

L-System fractal formula

Rule: F=FF-F-; (yes, same as above)
Angle: 60

Just changing the angle gives this snug triangular weave pattern at high orders.

L-System fractal formula

Rule: F=F--F+F-
Angle: 60

I have no idea what it is, but it makes a fantastic leaf template at order 7.

L-System fractal formula

Rule: F=FF[-F+F]FF
Angle: 60

An example of a tree or fern shape, this one very basic.

L-System fractal formula

Rule: F=FF[-F+F][+F-F]
Angle: 60

We took the same idea above and made it symmetrical; here it is in four generations at order 1, 2, 3, and 4.

L-System fractal formula

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

The good old dragon curve, in all its glory.

Perhaps I'll tuck into these again some time. A word of caution on fractals: they are guaranteed to push your computer's processing power to the limit, in just a few clicks! In most of these cases, doubling the last attempted order I showed you would probably be beyond anything but a mainframe. So if you try this on a laptop and the CPU fan is screaming, that's why. It is recommended that you start with order 1, then go up a step at a time, noting when your machine is starting to show signs of lag. Also, the dialog seems to be buggy and prone to crash at the mildest provocation, although that might just be my Ubuntu (is anything ever stable on Ubuntu?).

Some more ideas can be reaped from the Wikipedia page on Lindenmayer Systems. The language given there for various shapes can be translated into Inkscape's L-System dialog without too much effort.

If you're really getting into this toy and you're looking for some new challenges, here's the Wikipedia fractal list. Don't stay up too late, now!

Update Shout-out to TheBrickInTheSky, who continues an exploration of more Inkscape L-system goodness, in more depth than I can go into here.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

suddenly the moon