L-system Explorer

© 2002 Ron Coscorrosa, released under the terms of the GNU GPL

L-system Explorer Features

L-system Explorer is a program used for viewing and creating L-system fractals.

The following features are supported:

What are L-system fractals?

An L-system is a method used to model growth processes. They are named after Aristid Lindenmayer, who was the first to use them to model the growth of plants.

L-systems consist of an axiom (a simple string like "f"), and a set of production rules (such as "f=f-f++f-f"), and also an alphabet of symbols which have some pre-defined meaning and interpretation. The axiom is recursively expanded a fixed number of times according to the rules, after which a long string is generated.

Using the example above, the expansions would be:

Axiom: f
Rules: f = f-f++f-f

Level 0: f
Level 1: f-f++f-f
Level 2: f-f++f-f-f-f++f-f++f-f++f-f-f-f++f-f
Level 3: f-f++f-f-f-f++f-f++f-f++f-f-f-f++f-f-f-f++f-f-f-f++f-f++f-f++f-f-f-f++f-f++f-f++f-f-f-f++f-f++f-f++f-f-f-f++f-f-f-f++f-f-f-f++f-f++f-f++f-f-f-f++f-f

This long string by itself is useless unless some meaning or interpretation is made of it's symbols.

Traditionally, "f" means to go forward (drawing a line from the current point to the next point), while "+" and "-" mean to turn (right or left). For a full description of all the symbols, see the reference section.

Using an axiom and a few rules, it is possible to construct very complex and interesting fractals.

The best way to learn about L-systems are to experiment and try your own. In addition, the Fractint L-systems tutorial by William McWorter is highly recommended.

How to use L-system Explorer

Main window
When L-system Explorer starts up, a window will be displayed (which we shall refer to as the "main window"). On this main window there are two pull-down boxes at the top (labeled "Group" and "L-system"). The Group pull-down box selects which L-system group to use, and the L-system pull-down box selects which L-system to use within that L-system group.

Whenever a new L-system is selected, the following six fields on the main window are updated to reflect the properties of the selected L-system:

  1. Axiom - The L-system axiom
  2. Rules - A list of production rules.
  3. Initial Angle - Which way to face, initially (0 is considered north, 90 east, 180 south, etc.).
  4. Turn Angle - How far to turn when encountering a + or -
  5. Level - Initial depth to draw the L-system at.
  6. Scale - Used for the % command.
You may change any of these fields in order to experiment with your own L-systems.

There are two other fields on the main window: width and height, which determine the physical size of the L-system (the maximum of which is your screen height and width).

If you create an L-system that you like, you can save it so that the next time you start L-system Explorer it will show up. To do this, go to the file menu and choose "Save L-system" (or just hit CTRL-S), and you will be prompted for a group name and a L-system name to save the L-system under. You may use an existing group or create a new one. The L-systems are saved in the file ~/.lsysexp/lsyscustom. The format of this file is described in the lsyscustom section.

You can save various options via the preferences dialog which is accessible under the File menu. Current options include the default width and height of L-systems, the default background color, and default save path for images.

Finally, to actually display the L-system, click on the "Display" button. This will create an "L-system window" (you can have as many of these "L-system windows" open as you wish).

If you want to display all the L-systems in the current group, you can do so via the "Display all L-systems in Group" command in the File menu (there are usually 20-30 L-systems in a group, so 20-30 windows will be created - you have been warned).

L-system window
On each L-system window, there are three fields:

  1. Border - The size of the border or padding to use around the L-system in pixels.
  2. Noise - Amount of random uniform noise (i.e., distortion) to use. This is zero by default.
  3. Level - What level to display the L-system at
Changing these fields has no effect until you click on one of the three Draw buttons (Previous, Draw, Next), or choose "Draw L-system" from the file menu. The Prevoius and Next buttons draw the L-system at the previous and next level, respectively, while the Draw button draws the L-system at the current level. The current level is the level specified in the "Level" field.

The Mode menu allows you to determine how the L-system is drawn, whether to use lines (default), points, or a random combination of both. Traditionally, L-systems are drawn using lines, but it can be interesting to view them using just the endpoints of the lines as well. Changing the mode will automatically redraw the L-system to reflect the new mode.

The Colors menu allows you to change the colors of the L-system, as well as change the background color. If you want a boring single color L-system, you can choose "Single Foreground Color." All .map and .fmap colorings are under the Gradients menu, see the coloring section for details. You may also select a "Random Fade" (where a random gradient will be created), "Spectrum" (where a coloring using colors from each hue in the spectrum is created), or "Random" (which selects all colors randomly). To change the background color, select "Change Background...". Selecting an option in the colors menu will automatically redraw the L-system to reflect the new set of colors.

If you want to save an image of the current L-system, go to the File menu and select "Save L-system Image" (or hit CTRL-S), and you will be prompted for the filename to save under. The default image format is PNG, but if you type something ending with .jpg or .jpeg it will use the JPEG format.

Coloring (.map and .fmap files)

Version 0.55 added the support of .map and .fmap files. These files allow you to create your own custom color patterns. fmap stands for "fade colormap", and map for "standard colormap". Both .fmap and .map files will be referred to in this section as "map files."

Map files exist in two places:

Global maps:/usr/local/share/lsysexp/maps
User maps:~/.lsysexp/maps

If a user map file and global map file have the same name, the user map file will be used.

You can choose which map file to use under the Colors/Gradients menu. If the name of the map file is Foo.map, then you can use it by going to Colors/Gradients/Foo (If you have a lot of map files they will be split up into sub-menus under Colors/Gradients/ for convenience). If a fmap file as the same name as a map file, only one of them will be shown (in other words, don't name them the same! It wouldn't make sense anyway).

Each line in a map/fmap file represents a color, either specified by name (as used in the rgb.txt file distributed with the X, /usr/X11R6/lib/X11/rgb.txt on my system), or as an RGB triplet, with values ranging from 0-255 inclusive, and separated by whitespace. For example:

   255 0 0
   0 255 0
   0 0 255
   orange
   yellow
Would specify five colors, Red, Green, Blue, Orange, and Yellow.

Blank lines, and lines starting with "#" are ignored. Anything after the third color value in an RGB triplet is also ignored.

Regular .map files contain every color in the colormap (in Fractint, most of them are 256 colors, some are 16, etc.). If the .map file contains 3 colors, then the first 1/3 of the L-system will be the first color, the next 1/3 the second color, and the last 1/3 the third color.

With .fmap files, you specify a few colors (or however many you want), and it will fade smoothly between each of them, vs. you having to explicitly list all of them as you would with a normal .map. You can also stick "loop" on one of the lines and it will loop back, example:

Without loop:
black->red->yellow

With loop:
black->red->yellow->yellow->red->black

Fade map files are more useful in general, but normal map files are useful if you want to use the map files that come with Fractint, or just want single-color L-systems.

L-system Explorer Command Reference

The following are all the symbols which have special meaning to L-system Explorer.

Symbol Meaning
f Move forward while drawing a line
g Move forward, do not draw a line
+ Turn right A degrees, where A is the L-system turn angle.

Optionally preceeded by an integer X to turn right X times.

Example:

   3+
- Turn left A degrees, where A is the L-system turn angle.

Optionally preceeded by an integer X to turn left X times

Example:

   12-
@ Multiply the current line segment length by whatever number follows @ (this number can be a fractional or floating point number).

If @ is followd by Q and then a number X, the square root of the number X is used.
If @ is followed by I and then a number X, the inverse of X is used.
If @ is followed by IQ, or QI, then a number X, the square root of the inverse of X is used.

Examples:

   @3.14159
   @I2
   @Q7.3
   @QI5, @IQ5 (these both take the square root of the inverse of 5).
  
|Turn 180 degrees (reverse direction).

Note: This has no affect on the / and \ commands below, since you could just do /180 or \180 to get the same effect.

!Reverse the meanings of + and - (along with \ and /, see below).

In other words, all +'s encountered after a ! are treated as -'s, and vice-versa (unless another ! is encountered which switches the meanings of + and - back to the original).

%Move forward at a length dependant to the current depth and the scale factor. % is never expanded (unlike the other draw commands, which are expanded and only used at the final depth), so at every depth where it is encountered a line is drawn. The length of this line is equal to the depth raised to the scale factor.

Note: This command is has the same meaning as the | command from the book The Computational Beauty of Nature, but was renamed to avoid the conflict with the Fractint command.

[ Saves the current state (including x,y position, line length, direction, etc.). You may wish to think of this as pushing the current state on a stack.
] Restores the previous state saved by a ]. You may wish to think of this as popping the previous state off the stack.
The following 4 commands use a different "current angle" than the f, g, +, and - commands, but have a similar meaning (note: all commands share the same "x,y position" and "line length" attributes, it's only the "current angle" attribute that differs).

These are sometimes more convenient to use since you can specify the turn angles explicitly. They are also a little slower, since the turn angles have to be determined every time they are encountered.

If all of your turn angles share a common multiple (besides 1!), then you should use + and - (which you can proceed with an integer X to turn X times).

dMove forward while drawing a line
mMove foward, do not draw a line
/XTurn right X degrees, where X is an integer or floating pointer number.
\XTurn left X degrees, where X is an integer or floating point number.

General syntax notes:

  1. Whenever a number is expected, it will be gobbled up until a non-digit is encountered (except for floating point numbers, where a '.' is also allowed). That means that:
    f@5.34+f
    
    is different from
    f@5.3 4+f
    
    In the first case, the complete number is gobbled up, and then a single turn to the right is made, in the second, a non-digit is encountered (a space), and then four right turns are made. You can usually avoid cases like these, but if not, just stick in a space or some other meaningless character to separate the numbers.

  2. All production rules must start with a letter, a-z (this also implies that there can be at most 26 rules).

  3. All letters are automatically converted to lowercase.

  4. Unknown characters are ignored.

Differences from Fractint

lsyscustom format

When you first save an L-system, a file called "lsyscustom" will be created in ~/.lsysexp/ which contains a description of that L-system. Every additional L-system you create and save will be appended to this file. The format of this file is described below, in case you want to add L-systems by hand, or remove L-systems that you have saved.

Each L-system starts with a { followed by a new line, and ends with a } followed by a new line. In between the { and } are the fields, which have the format field_name : field_value, followed by a new line.

Valid field names are:

Field NameDescription
group Name of the group where the L-system should be placed
name Name of the L-system
axiom Axiom of the L-system
rules A rule of the L-system (there may be several of these, one per each rule).
level The default recursion level to use for the L-system
a0 The initial angle for the L-system, in degrees
da The turn angle for the L-system, in degrees
ds The scale factor for the L-system

The field names can appear in any order. If a field is repeated (besides rules), the lowermost field is used.

You should be able to figure out what's going on by looking at the file, as it's pretty straight-forward.

Utility Scripts

Here are a few scripts which you might find useful. To use them, just copy them somewhere and make them executable. Details on how to use the scripts are listed at the top of each script.

Credits and Contact

L-system Explorer was written by Ron Coscorrosa

The webpage for L-system Explorer can currently be found at http://www.cs.pdx.edu/~coscorrr/programs/lsysexp.

Thanks to:

The majority of the L-systems were taken from the Fractint archive at http://spanky.triumf.ca/pub/fractals/lsystems/. Thanks to William McWorter, Gary Teachout, Anthony Hanmer, Ole Jorgensen, Michael A. Rouse, Jaume Bartroli, José Torres, Adrian Mariano, and Ken Philip.

Part of the L-system interpreter code, and several other design issues were inspired from the code given by Gary William Flake in the accompanying source code to his (excellent) book The Computational Beauty of Nature.

Many of the color routines were converted from Jamie Zawinski's XScreenSaver package.


Copyright © 2002 Ron Coscorrosa