home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
graphics
/
fractal_1
/
!Fractal
/
Help
/
L-Systems
< prev
next >
Wrap
Text File
|
1995-09-05
|
14KB
|
314 lines
________________________________________________________________________
/ \
| !Fractal : Help On L-Systems |
| |
| September 1995 |
\________________________________________________________________________/
L-System : Turtle graphics as used for drawing plants etc.
--------
The L-system uses a LOGO like turtle language to describe shapes as a series
of movements, and was introduced by A. Lindenmayer to help describe plants.
Refer to the book The Algorithmic Beauty of Plants for full details of the
work by Prusinkiewicz and Lindenmayer. Up to 80 definitions are stored
internally, and can be saved as a text file, or a new file may be loaded.
Each shape definition is made up of the following components:
Name: 1-19 character name for identification.
Iterations: the number of times the algorithm is recursively expanded.
Angles: Rather than describing the amount of each turn as so many degrees,
each turn is expressed as a fraction of a circle. Thus 6=60° (360°/6). The
number should be even if you plan to use the '|' command to allow turns of
180°.
Axiom: a string of 1-255 characters incorporating turtle commands and rules.
Rules: a single letter identifier and 0-255 characters consisting of further
rules or turtle commands. Note that the case of letters is significant.
The routine starts by taking the axiom string and then replaces each rule
character in it by the equivalent rule string. This process is repeated
for the number of iterations specified.
Thus if the axiom is F-F and the rule F=F+F, after the first expansion we
get : F+F-F+F, then F+F+F+F-F+F+F+F, and so on.
After expansion the string is interpreted as a series of turtle commands,
any rule characters being ignored.
The key to the routine is this recursive expansion, and often the use of
F as a rule and turtle command (which is somewhat confusing I admit, but
very important).
Drawing
-------
Because the size of the image is unknown at the outset, the plot has to be
repeated, with the image being correctly scaled to fit on the screen on the
second pass. However you can use zooming or turn off Auto Scaling (see
later), in which case only a single plot is performed.
Use Adjust to stop a plot. Note that currently it is not possible to restart
a plot after Adjust is pressed. You are advised to start at low iterations
and work up.
Basic Turtle Commands
---------------------
The characters used are those in standard use. Note that 'F' is different
from 'f'. (Fractint uses 'G' for 'f' since it is case insensitive).
Initially the unit line length is 1 and the direction is along the x-axis.
F : draw a line forwards in the current direction and length.
D : same as F, ie. draw a line forwards.
f : move forwards without drawing a line.
- : turn anti-clockwise 1 angle (see definition of angle above).
+ : turn clockwise 1 angle.
| : turn 180°. Note - angle must be even for this to work correctly.
Advanced Turtle Commands
------------------------
To get more complex displays requires the use of one or more these commands.
[ : stack the current position, angle, line length, width and colour.
] : unstack the turtle details.
! : reverse meaning of '+' and '-'.
cn : Set colour to n where n=0-255. See below for colour numbering.
>n : increment colour by n where n is one or more digits.
<n : decrement colour by n.
@n : multiply the line length by n. The initial length is 1. 'n' is 1 or
more decimal digits and may contain a decimal place.
To divide precede the number by I (for inverse). eg. @I3 divides by 3,
or use @0.333.
Precede the number by 'Q' for the square root, eg. @Q2 = length * 1.414
#n : Multiply the line width by n - the initial width is a single pixel.
Numbers may be specified as for line length.
{sprite} : Plots a sprite of this name at the current position and rotation.
The sprite is plotted the same size as the current line size.
See below for full details.
{sprite,n} : As above but plots at the scale specified as 'n'.
Colour
------
The initial colour is 255 (white in the default palette). To get a sensible
progression of colours use the RGB palette.
If the colour exceeds 255 it wraps around. If a colour falls between 0-7
when using < or >, then it is incremented/decrmented by 8, since colours 0-7
are assumed to be too dark to be seen.
Menu Options
============
The menu options are described next.
Data Entry Panel
----------------
Use this panel to update the L-system data, or select a new L-system. To
move the caret around the icons use !Fractal's standard editing keys. The
various icons are:
Input: You must click on this for your changes to take effect.
Re-draw: This is the same as Input followed by a re-draw request.
Store: This takes the data and stores it in the internal file. If you move
to another L-system without using this option your updates will be lost!
Restore: Refreshes the data on display from the copy in the internal file.
This lets you back out changes without having to re-load the file.
Copy: Takes a copy of the current L-system so that you can edit it without
modifying the original. You should give the copy a new name to avoid
confusion.
Delete: Deletes the current L-system from the internal file.
Name: the 1-19 character identifier for this L-system.
Item: click on the left or right arrows to move to a different L-system.
Remember to use Store if you want to keep any changes to the current
L-system.
Iterations: Use the arrows to change or click on the number to key in a new
value. Higher iterations give more complex patterns but will take much
longer to draw.
Angle: determines the amount of turn for '+' and '-'.
Axiom: the 1-31 character string that is the initial rule.
Rules: Each rule must have a unique character for identification. Up to 9
rules may be use, each of 0-79 characters. A null rule can be used to strip
out turtle commands during expansion (see Cesaro for example). Remember to
click Input or Redraw to enter your values.
L-System List Panel
-------------------
This panel lists all the L-systems that are held internally, showing the
first 11 characters of their name with the current name being highlighted.
Click on a name to select one. The predefined shapes all assume that the
Default palette is in use - this is mainly of importance when plotting the
plant shaped images.
Save
----
The internal file of L-system definitions can be saved as a text file by
dragging the text icon to a filer window. The associated sprites will be
saved in the same directory if not already present. Saved definitions can be
reloaded at any time - !Fractal will automatically select L-system if it is
not the current fractal. Three files of definitions are supplied - click on
Misc->Resouces to open a Filer window showing the files available.
You can edit the text file, but be careful to keep to the format which is:
L-System
sprite filename
Name=l-system name } for each
Iter=iterations } L-System
Angles=no. angles }
Axiom=axiom string }
ruleid=rule text } 1 for each rule
The supplied definitions come from the Science of Fractals, Algorithmic
Beauty of Plants, Fractint, and John Greening. Please send in more functions
to AFG so we can all see them. I have added colour and sprites to some of
the shapes.
Auto Scaling
------------
When on this ensures that the image is automatically scaled to the maximum
displayable size. Turn it off if you want to manually position the image -
this is useful if you want to plot multiple shapes and place each at a
certain position. To do this turn Image->Redraw->Clear off and manually set
the x0/y0 (bottom left coords) and width/height values in the Image->Data
panel. Remember that a unit length is 1 and plotting begins at 0,0. The best
way to determine the values required for a shape is to draw the shape with
auto scaling on, then use Display->X/Y Position to find the co-ordinates
required.
The best way to create multiple shapes is to use the Script feature.
Fill
----
When on invokes the CellFill function. This is useful for space filling
curves such as the Hilbert or Peano, since it proves they are indeed just a
single line. See the CellFill function for further details and options.
Hints And Tips On Creating L-Systems
====================================
To get an idea how L-systems work, look at the shapes prefixed 'Sier' and
start at low iteration values. Note that shapes grow because a rule string
contains more than one rule.
A good way to trace how a shape is built up is to add a colour change at the
start or end of a rule, ie. add a >4 or >1. The different colours in the
result show where a new copy of the rule was expanded. Try the colour
cycling on this as well!
Shapes that are made up of lots of smaller copies of themselves are created
by making the rules recursive, that is the rule string contains the same
letter as the rule name (eg. F=FF) or a subsequent rule refers back to the
first one (eg. F=AB, A=FB).
To set the initial direction, width or colour, place the required turtle
commands in the Axiom. The initial direction is to the right so use '-' to
make a shape start plotting upwards. That way they are only executed once -
see Bush3 for an example.
The stack is a very powerful feature and worth experimenting with - it is
the key to shapes that feature points, such as the plant examples. It also
allows you to create a sub-shape with its own colour, size and width which
may be placed anywhere within the main pattern. See Tree3 which uses 'L' for
the Leaf rule. Typically these sub-shapes are placed at the end of a stacked
sequence - PlantLeaf uses [--L] to place a leaf at the tip at particular
points.
Two draw commands (F and D) are provided so that one may be expanded (by
making the command a rule) and the other unexpanded. Tree3 uses this to
allow the leaves to be drawn the same size. If the L rule used 'F' for
drawing, the 'F' rule would expand making the leaf larger depending on where
it was drawn - try it and see.
The length command (@) is generally used to make successive parts of the
shape relatively smaller. See Tree1 for example which uses it to make the
branches smaller and smaller. A similar effect can be achieved by using a
rule of the form F=FF - at higher iterations each F character is expanded
into more F draw commands.
Use the width command (#) to give body to plant and tree shapes for extra
reality.
Sprites
=======
The sprite plotting feature is a powerful extension to the normal command
syntax. Instead of using F to draw a line specify the name of a sprite, which
will be plotted at the same length as the line and at the same rotation. To
avoid long rule lines it can be useful to use a rule for a sprite eg.
P=+T-TT++T
T={trunk}
Plotting with sprites will take longer, and it is often better when creating
a new shape to start off with the outline, then substitute the sprites at a
later time.
Creating Sprites
----------------
The following guidelines must be followed for plotting to work correctly.
The sprites are contained in a sprite file in the same directory as the
L-system definitions. The name of the sprite file is specified in the second
line of the L-system definition file.
The supplied sprite file is called "L-Sprites" - click on Misc->Resources to
locate. Look at the example sprites provided to get an idea of the
requirements, which are:
1) The sprite must be square and should be a multiple of 4 pixels in size.
2) A 256 colour must be chosen that has square pixels, such as mode 21 or
mode 13.
3) The sprite should be created with a mask. All pixels that are not to be
plotted should be set to the mask colour so these pixels become transparent.
4) When creating the shape bear in mind that top is to the right since that
is the initial direction of plotting. You may find it easier to create the
shape and rotate it 90° clockwise.
5) Since the sprite gets rotated, pixels in the corners will tend to get
lost at angles other than 0,90,180 & 270 degrees. To avoid black space
however, you will normally need to set pixels up to the edge of the sprite.
The above rules are necessary because of the scaling and rotation that is
performed. If you get strange results, check that you have followed these
guidelines. The main limitation on the size of sprites is the amount of
memory in your computer. Large sprites will soon consume all that is
available. Sizes from 16-64 pixels should be adequate for most purposes.
Larger sprites will tend to look better when scaled and rotated - small
sprites will look more distorted. To maintain clarity try to avoid too much
detail in the sprite.
To reload a sprite file after editing, simply drag its Filer icon onto a
!Fractal window/icon, or drag the Save icon from !Paint.
Using Sprites
-------------
The sprite name is specified by {spritename} in a rule definition. If the
sprite cannot be found, it is ignored. The sprites are displayed at the
current line scale no matter how large the sprite is. To plot the sprite at
a different relative size use {spritename,9.9} where '9.9' is the scaling
factor.
The size of sprites is also controlled by the line length specifier '@' -
this allows sprites to be plotted at increasingly smaller (or larger) sizes
which is useful for plant like shapes.
Sprites can be used with the all the other plotting commands, though the
colour and width commands do not affect the sprite. Interesting effects can
be achieved by taking the shapes provided and replacing the 'F' commands by
a sprite. To do this it will be necessary to preserve the recursive nature.
Thus if the original rule was F=F+F-, then the replacement rule would need
to be S=S{sprite}+S{sprite}-.
To avoid out of memory conditions it is best to use a number of L-system
definition files with their own sprite files. To create a new file delete
the entries not required, and save the remaining definitions under a new
filename. Then edit the text file to specify a new sprite file name.