DIY Fractal

L-System Fractals

The image at the upper left of this webpage was generated using a very simple program written in MSWLogo.

The fractals that are easily drawn by Logo are L-systems or "Lindenmayer System" fractals. (http://www.cogs.susx.ac.uk/users/gabro/lsys/lsys.html) An L-system is a type of grammar that specifies rules which can be iterated to form self-representive images. Given one rule, an entire fractal can be drawn. Here are some examples below:

Let's start with the c-curve. The basic unit of these fractals is the straight line. The first iteration of the c-curve is a second line perpendicular to the first:

The method of drawing this fractal is to first draw a line, make a 90 degree angle, then draw another line. Actually this is incorrect...somewhat. It is difficult to see in this picture. Perhaps it would be clearer this way:

As you can see, each iteration of the fractal replaces all the lines with a 90 degree L-shape.

First a line is drawn. Then two, then four.

The first iteration is the line.
second iteration: make the 90 degree L-shape.
third iteration: make two of the 90 degree L shapes.

You may be wondering how this can create the iterations above. Well, we write the entire bit of code to produce the c-curve just by knowing the first and second iterations, and then we use recursion.

ok, so we know to draw a line and we know then we have to draw two lines, then four...

well, what we can start to see is that each time a line should be drawn, it can be replaced with the two lines at a 90 degree angle...

The pseudocode for the first iteration looks like this:

first iteration:

draw a straight line

second iteration:

draw straight line

turn right 90 degrees

draw straight line

turn left 90 degrees

third iteration:

draw straight line

turn right 90 degrees

draw straight line

turn left 90 degrees

turn right 90 degrees

draw straight line

turn right 90 degrees

draw straight line

Now, I said we only needed to know the first and second iterations. Actually the second is the most important. It is the basic structure of the fractal. Let's look at the pseudocode for it:

draw straight line
turn right
draw straight line
turn left

We know each of those "draw straight line" could actually be this shape too, so what if instead of drawing a straight line, we just drew another L-shape? The way to do this is to run this fractal routine recusively. Here's what I'm talking about:

call c_curve
turn right
call c_curve
turn left

The only issue is that we don't actually draw a straight line with this code. So we add a functional argument, :iterations.

A variation on this fractal is the dragon curve. The dragon curve appears very complex, however it is based on a simple c-curve. Let's look at the iterations:

Iterations one and two are identical to the c-curve, however we see that the L-shapes alternate inside and outside the lines. Instead of replacing each line with the L-shape, each line is replaced with alternating L-shapes. To achieve this, we must introduce another variable. Here, I used the variable :angle (which I always intially set to 90 when calling) to provide the alternation:

This image was generated with length of two and iterations = 5. Now, this is interesting, but what if we start with a closed shape instead of a line? We can generate the famous Koch snowflake with these iterations:

The basic first shape is the triangle, which is drawn with a separate function, however for each of the sides, the Koch Snowflake routine calls koch. The resulting code in Logo is this:

Here is a quirky little fractal that I am playing around with now. It is somewhat a variation on the Koch curve in that it's structure is like this:

I was experimenting with waveforms at different iterations, and this is the first interesting one I came across. The waveform is digital, and exhibits a spike in the sample. For this reason, I entitled it "digital blip."

The image was created with length of one and only six iterations. It is interesting to note all the circular shapes that were formed from its very square basis. The overall shape almost appears to be a cross, and is quite gothic in appearance. Perhaps this fractal is in need of a better name.

Here is another view of it, repeated four times in the shape of a square: