A short introduction to fractals and L-systems, as used in the SimpleFractals application.

Fractals.

Here, how Math World defines fractals: A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not exhibit exactly the same structure at all scales, but the same "type" of structures must appear on all scales. A plot of the quantity on a log-log graph versus scale then gives a straight line, whose slope is said to be the fractal dimension.

Or somewhat simpler: A fractal is basically a geometric figure, that shows the same characteristics no matter how much you zoom in.

Turtle graphics.

Turtle graphics was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966 and intended to introduce programming to kids. Some modern programming languages, such as Python contain a turtle module. The principle of turtle graphics is simple:Let the turtle (the pen on your drawing surface) execute a series of commands in order to plot, whatever you want. Basic Turtle graphics commands and options:Move forward, turn left, turn right, disable writing, enable writing.

Fractals are geometric figures, composed of pattern, that repeat again and again, we said. Thus, why not using Turtle graphics to draw them:Starting from an initial figure, within successive iterations, transform the figure to a new one, being the repetition of itself, corresponding to the actual iteration step and continue this procedure, as long as we want, being limited, of course, by the resolution of the graphics display. So far, so good. But how to do, to implement the figure repetitions in an easy way? Is this even possible? The answer is yes. By using an L-system!

L-systems.

Definition, according to Math World:A Lindenmayer system, also known as an L-system, is a string rewriting system that can be used to generate fractals with dimension between 1 and 2.

Or, with other words:An L-system is a way of representing recursive structures (such as fractals) as a string of characters, this is done by rewriting the string over and over.

Components of an L-system.

Every L-system has:

As we are going to use Turtle graphics to plot and L-systems to represent what we want to plot, we need to create a relationship between the alphabet symbols and the Turtle commands. We can assign a symbol to each of the Turtle commands, mentioned above, and these symbols will represent the alphabet of the L-system; for example:

    F:   Move forwards
    +:  Turn right
    -:   Turn left

Moving forward meaning here drawing, while moving forward and turning right resp. left meaning turning by a given angle, that, as the axiom and the rules, has to be defined as part of the L-system. To take into account the disable writing option of Turtle graphics, we can extend our alphabet by a further symbol:

    G:  Move without drawing

This 4-symbols alphabet is rudimentary and will only allow to draw simple fractals. For more complex drawings (in particular biological structures, such as trees and plants), further L-system commands will be needed, the most common would be:move backwards, remember (push to stack) turtle position, restore (pop from stack) turtle position. There are even L-systems, that include symbols, doing arithmetic operations, such as incrementing or decrementing the line width or the angle.

Except (probably) for F, there isn't a real standard for the symbols used in L-systems. Move forward without drawing is sometimes represented by f (instead of G) and the turn commands are often considered by the mathematical way of seeing angles (positive angle, turning to the left), thus, you'll find L-system definitions, where + means turn left and where - means turn right.

Depending on the complexity of the fractal, several rules may be needed to define it with an L-system. This makes necessary an extension of the alphabet by what I call placeholders (placeholders are also sometimes necessary in one-rule L-systems). These are symbols, that may appear within the axiom and/or the rules, without having any effect on the turtle, but being replaced by a new command string at each iteration. Often X and Y are used as such placeholder symbols, but you'll find L-systems, that use A, B, C, D or other letters. Concerning multiple-rules L-systems, it is important to know, that all rules have to be applied simultaneously, that is independently the one from the other on the previous iteration string.

Examples:

Levy C-Curve axiom = "F"
 rules = {"F": "+F--F+"}
 iterations = 12
 angle = 45
Hilberts-Curve axiom = "L"
 rules = {"L": "+RF-LFL-FR+", "R": "-LF+RFR+FL-"}
 iterations = 6
 angle = 90

In the first example, at each iteration, each F of the previous iteration string is replaced by the string described by the rule. The second example has two rules, telling that at each iteration the placeholders L and R have to be replaced by the corresponding string. Remember, that there is no rule priority, but that rules have to be applied simultaneously.

The SimpleFractals application.

SimpleFractals is a PC application, that uses basic L-systems to draw simple fractals. The alphabet is made of the following symbols:

    F, G, +, - Turtle commands, as described above
    V, W, X, Y, Z Placeholders, as defined above
    0..9 Color codes (see below)

To simplify the L-system definition parsing, if there are more than one rules, these have to be written one per line at subsequent lines.

Non-standard L-system parameters.

As fractals are mathematical structures, it is possible to do a complete mathematical analysis of them and doing so, determine where the drawing will appear on the graph. SimpleFractals uses another way, to ensure that the fractal is drawn centered on the drawing surface, by extending the L-systems syntax by the (non-standard) parameter origin = (x,y), where x and y are the coordinates, where the turtle has to be placed, before starting to draw. Another variable, that affects the proper drawing of the fractal, is the length of the turtle displacement. Also note, that, in some cases, this displacement has a modifying effect on the fractal image. SimpleFractals allows the specification of a (non-standard) parameter displacement = d, where d is the displacement, that does the turtle each time, when an F or G command is executed.

Colored fractal drawings.

It's obvious, that the pictures produced are lots prettier if colored, than if just drawing black on white or green on black. I found a very simple way to add color to most (not all) classic fractal drawings: I extended the alphabet by the (non-standard) color codes 0..9. Their meaning is, that each time one of these symbols appears in the command string, the color of the turtle-pen is set to a given value (predefined values: 0=red, 1=orange...). As these symbols are my "personal invention" (thus never used in fractal definitions, that you find in some book or at some website), they may turned off in the application's Settings menu; opening a .sfl file, with color drawing disabled, will automatically remove the color symbols and load a standard L-system definition (except for the origin and displacement parameters, not mandatory, and possible to be entered into edit fields on the application's form).

[text mostly based on Step by Step Fractals with Python by Ezequiel Leonardo CastaƱo]