This is a demo that I wrote for my students so that they can play with Lindenmayer systems. The program was created using the Common Lisp compiler from LispWorks. You can download it from
http://weitz.de/files/Lindenmayer.zip
.You are free to use this software for private or educational purposes. (But you are of course using it at your own risk.) However, redistribution of any kind is not allowed without written permission. If you want to give this program to someone else, point them to the original download location at
http://weitz.de/lindenmayer/
.
[CLICK ON THE VARIOUS PARTS OF THE IMAGE ABOVE FOR MORE INFORMATION.]
The usual way to use the application is to either load or edit an L-system, then parse it and then draw some of its generations. You should probably start with some of the examples which are distributed together with the program.
You can also at any time save the current image or you can zoom into it.
In order to understand the following you'll need a basic understanding of Lindenmayer systems.
On the right side of the application there's a simple text editor which you can use to enter system descriptions. (Or you can use another editor and load a system description via the menu.) A system description consists of productions and an axiom and it can optionally contain translations and specifications about angles. The details are explained in the following paragraphs.
System descriptions are simple text files and are read and interpreted line by line. A line that contains the four-character sequence ␣->␣ (including the spaces at both ends) with one non-space character in front of it (the predecessor) is regarded as a production with everything behind this sequence being the replacement (i.e. the successor). (So we obviously only accept context-free L-systems.) All non-whitespace characters are legal symbols on both sides of a production, including - and > from above.
As the screenshot above shows, it is possible to have productions where the right side is empty. You just have to make sure that there's really a space behind the -> arrow.
A line that starts with Axiom:␣ specifies the axiom of the L-system which again can be any sequence of non-whitespace characters.
You can also optionally have lines starting with Angle:␣ and StartAngle:␣ which specify the angles described below. (But you can also use the angle panes to change these angles dynamically.) The angle must be an integer between 0 and 90. The start angle must be one of the values 0, 90, 180, 270, or 360 (the latter being a synonym for 0).
Finally, any line that contains the four-character sequence ␣:=␣ (including the spaces at both ends) with one non-space character in front of it is regarded as a translation. The system will compute the requested generation according to the productions, but it will replace characters following these translations rules before the generation is drawn. (For an example of how translations can be used, see the file tree.l.)
Whenever you make a chance to the system in the editor, the editor's background color changes from white to light red and the drawing buttons are disabled. You then have to press the parse button to parse the system and draw the axiom.
Drawing is done with the corresponding buttons or with keyboard shortcuts. This section explains what is drawn and why.
A generation of an L-system is just a string of characters. To draw such a generation, each character is looked at in turn an processed as if by some kind of turtle graphics. The following characters are recognized as turtle commands.
All other characters are ignored. The turtle will initially walk into the direction specified by the direction pane or by the start angle parameter. The angle used for the + and - commands is the one specified by the angle pane or by the angle parameter.
The distance traveled by the f and F doesn't matter (except that it's always the same) because the program will make sure that the final drawing will always fit the screen.
The four buttons next to each other all have the effect that a specific generation is computed and then drawn. In order from left to right, the axiom (i.e. the '0th' generation), the previous generation, the current generation, and the next generation are drawn whereby terms like 'previous' or 'next' refer to the current generation which is the one shown in the generation display. Pressing the button to draw the current generation won't change the display unless you had just zoomed into an image.
The button directly below the system editor is the parse button. If you press this button, the system in the editor pane is parsed and its axiom is drawn. This will also switch the editor's background color from light red to white unless there were errors in your system description.
The square pane entitled 'Angle' can be used to set the angle which affects the drawing commands + and -. You change the angle by clicking with the mouse or by moving it while holding the button. You can also right-click to get a menu with 'typical' angles.
The square pane entitled 'Direction' can be used to set the angle the 'turtle' uses initially. You change the angle by clicking with the mouse. There are only four possible values - North, South, East, and West.
Both angles mentioned above can be overriden each time a system which contains angle parameters is parsed.
You can use the menu to load text files into the system editor and also to save the editor's contents to a file. If you want to use an external editor, the Reload L-system menu entry might come in handy because it'll allow you to load a system from a file and then quickly reload it whenever you've made changes to it.
Use the Save image menu entry to save the contents of the main output pane as an image. You'll have the option to choose between the file formats PNG, JPEG, TIFF, and BMP.
Finally, the Paste status menu entry will update the contents of the editor pane with the settings made in the angle panes.
The large white pane on the left is where generations are drawn. It'll also provide you with the ability to zoom into a picture: If you move your mouse over the drawing and the cursor becomes a magnifying glass, just click somewhere to zoom in.
Zooming is limited, though. The program doesn't draw directly onto the output pane but instead it uses an internal buffer which is somewhat bigger (unless you have a very big screen). You can only zoom in up to the point where you see a full-scale section of this buffer.
To zoom out again, click the mouse while holding the Ctrl key. Or press the button with the pencil to zoom out completely.
The long line below the main output pane shows which generation of the current L-system you're in (whereby the axiom counts as generation zero) and it shows the first few hundred characters of the current generation. This can be used for debugging if you're trying to develop your own L-systems.
Most of the things that can be done with the mouse can also be done with the keyboard. Here's a list of all keyboard shortcuts: