linden.icn: Program to generate sentences in 0L-systems

June 21, 1999; Ralph E. Griswold
Requires: graphics if drawing
This file is in the public domain.
This program reads in a 0L-system (Lindenmayer system) consisting of
rewriting rules in which a string is rewritten with every character
replaced simultaneously (conceptually) by a specified string of
symbols.

Rules have the form

     S->SSS...

where S is a character.

In addition to rules, there are keywords that describe the system and how
to draw it.  These include the "axiom" on which rewriting is started and
optionally the angle in degrees between successive lines (default 90).
Other keywords may be present, but are ignored.

Keywords are followed by a colon.

  An example 0L-system is:

     X->-FX++FY-
     Y->+FX--FY+
     F->
     -->-
     +->+
     axiom:FX
     angle:45.0
     xorg:100
     yorg:100

Here, the initial string is "FX" and angular increment is 45 degrees.
Note that "-" is a legal character in a 0L-system -- context determines
whether it's 0L character or part of the "->" that stands for "is
replaced by".

If no rule is provided for a character, the character is not changed
by rewriting. Thus, the example above can be expressed more concisely
as

     X->-FX++FY-
     Y->+FX--FY+
     F->
     axiom:FX
     angle:45.0

The recognized keywords are:

     axiom   axiom for generation
     angle   angular increment for turns
     length  segment length
     xorg    x origin
     yorg    y origin
     comment comment; ignored

Distances increase from left to right in the x direction and from top
to bottom in the y direction.

As pure-production systems, the characters are symbolic and have no
meaning.  When interpreted for drawing, the characters have the
following meaning:

     F       move forward by length
     f       move backward by length
     +       turn right by angle
     -       turn left by angle
     [       save current state
     ]       restore current state

The file containing the 0L-systems is read from standard input.

The command-line options are:

     -g i    number of generations, default 3
     -l i    length of line segments, default 5
     -a i    angular increment in degrees (overrides angle given in
               the grammar)
     -w i    window width
     -h i    window height
     -x i    initial x position, default mid-window
     -y i    initial y position, default mid-window
     -W      write out string instead of drawing
     -s      take snapshot of image.
     -d i    delay in milliseconds between symbol interpretations;
               default 0

NOTE:  The name option that supported multiple L-Systems in
       one file has been eliminated on the grounds that it
       introduced too much complexity in use.
____________________________________________________________

References:

   Formal Languages, Arto Salomaa, Academic Press, 1973. pp. 234-252.

   The Algorithmic Beauty of Plants, Przemyslaw Prusinkiewicz and
   Aristid Lindenmayer, Springer Verlag, 1990.

   Lindenmayer Systems, Fractals, and Plants, Przemyslaw Prusinkiewicz and
   James Hanan, Springer Verlag, 1989.
____________________________________________________________

See linden.dat for an example of input data.

Source code | Program Library Page | Icon Home Page