How to Build and Use an L-System
Definition
Create
Your First L-Systems
Key for
Special L-System Symbols
L-systems differ from Chomsky grammars in that all variables are replaced in each step, and not just one. For example, with the replacement rule “G → g G G f”, and with an axiom, or initial state, of “G G”, the first derivation,of the system would be “g G G f g G G f”. the second derivation “g g G G f g G G f f g g G G f g G G f f”, and so on.
JFLAP
defines an L-System as follows:
Σ is the finite alphabet of the
L-system.
A ∈ Σ+ of the finite length of the axiom
R = {(a, b, c) → d | a, c ∈ Σ^{*}, b ∈ Σ, d ⊂ Σ^{*}}
For any (a, b, c) → d ∈ R, if |d| > 1 the L-system is a stocastic L-system, and if a ≠λor c ≠λthe L-system is a contextual L-system.
Note: In JFLAP, all unique symbols are separated by spaces. This means that entering “g g” would be considered as representing two unique instances of “g”, and entering “gg” would be considered one instance of the unique symbol “gg”. This is in contrast to how JFLAP implements other tools such as grammars, in which every symbol is processed separately.
To create a new L-System, start JFLAP and click the L-System option from the menu, as shown below:
One should then see the screen below. Notice the three parts of the window that will be important for entering our L-system. The first is the “axiom” area, which consists of the “Axiom:” label in the upper-left of the screen and the text box to the right of it. The second is the panel below the axiom area, which is where we will enter the replacement rules for our L-system. Finally, the third part is the panel with the “name” and “parameter” columns, where one can change any parameters used in animating the L-system.
Now, let's enter our first L-system. Enter “X” for the axiom, and “X → g g g X + g” as a replacement rule, or load the file lsystem1.jff. You should see the screen below:
When finished, click on the “Input → Render System” command in the menu bar. The following screen should come up:
There are many things to notice on this animation screen. The large middle area is where the animation will occur. There is nothing there at present, but there will be at higher derivations. The bar in the upper left tracks how long it takes for the current L-system to load. In lower derivations JFLAP takes little time, although it takes more at higher ones. The middle of the upper bar shows the axiom at the current derivation. Since the screen is currently in the zeroth derivation, there is just an “X”. In the upper right there is a derivation spinner, set at “0”, which allows the user to adjust the current derivation. Let's use that now. Use it to change to the first, second, and third derivations. With each derivation, you should see drawings and axioms resembling the ones below:
Derivation 1 |
Derivation 2 |
Derivation 3 |
---|---|---|
In the first derivation, we can see a line, part of which veers to the upper right. This is drawn by what is termed a “turtle”, which draws the commands given to it. You may wonder what exactly these commands are. There are two unique commands in the example above that we have given the turtle, “g” and “+”. “g” tells the turtle to move forward a preset distance with the pen down, meaning that it draws a line as it moves forward. “+” tells the turtle to turn right a few degrees, in this case the default 15°. Through the three derivations, we can see what happens as each time the X is replaced by new symbols and the graph interprets them. The line gets longer and curves more the higher the derivation is, due to the presence of more “g” and “+” symbols. Other characters, such as the “X”, have no effect on the turtle as it processes a derivation.
Now is a good time to notice the “Pitch”, “Roll”, and “Yaw” spinners in the lower part of the screen. These will rotate your drawing in a specified direction in 15° increments, depending on the particular spinner. The “Pitch” will rotate the object around the x-axis, the “Roll” around the y-axis, and the “Yaw” around the z-axis (defining the x-axis as the horizontal axis, the y-axis as the vertical one, and the z-axis as the implicit axis perpendicular to the screen). Go ahead and rotate the image as you see fit. Notice that a spinner cannot be less than 0° nor greater than 345°.
Let's try a different example. Close the current animation, and either enter the information found in the screen below, or load the file lsystem2.jff. When finished, you should see the screen below...
The first rule has three new symbols. The “~” symbol decrements the width in lines drawn by the turtle. The “[“ and “]” symbols store the symbols between them and state of the turtle (position & parameter values) on a stack for processing later. The turtle continues with processing symbols following the “]”, and will eventually come back to process the brackets and the symbols between them with the saved state of the turtle. This allows for the user to create a branch. You may also now notice that we are entering new parameters in the bottom panel. These will overwrite the default values for the animation. For example, instead of the turtle moving 15° to the right when a “+” is read, it will now move 30° thanks to the new value under the “angle” parameter. Now, let's try out our new L-system. When you render it, you will notice that it draws a fairly thick line with small spurs issuing from it in 30° intervals. The following is a picture of the screen in the tenth derivation.
Let's do one final example. This time, we are going to make and draw a tree. Close the current animation, and either enter the information found in the screen below, or load the file tree.jff. When finished, you should see the screen below...
We are using a number of different symbols that we haven't used before. For example, the symbol “%” rotates the turtle 180°. The “{“ and “}” operators allow one to fill in solid polygons, with each new position reached by “g” a vertex. The ## and @@ operators increment and decrement the hue colors of the polygon, respectively. When rendered, after a suitable number of derivations you should notice a tree that has different colors the higher it gets. A drawing of the tree in the tenth derivation is shown below. This is the last example, but please note the key below which explains the turtle commands that JFLAP recognizes.
Symbols
g → move forward one unit with the pin down
f → move forward one unit with the pin up (note: does not establish a polygon vertex)
+ → yaw the turtle right by angle degrees (aka turn right along the xy plane)
- → yaw the turtle left by angle degrees (aka turn left along the xy plane)
& → pitch the turtle down by angle degrees
^ → pitch the turtle up by angle degrees
/ → roll the turtle to the right by angle degrees
* → roll the turtle to the left by angle degrees
% → change direction 180 degrees
! → increment the width of the next lines
~ → decrement the width of the next lines
[ → save in stack current state info
] → recover from stack state info
{ → start filled in polygon
} → end filled in polygon
# → increment the huge angle of color by hueChange
@ → decrement the huge angle of color by hueChange
## → increment the huge angle of polygonColor by hueChange
@@ → decrement the huge angle of polygonColor by hueChange
Parameters
color → the color of the line (default is black).
polygonColor → the color with which polygons are filled (default is red)
distance → the amount the g and f commands move the turtle forward (default is 15 pixels)
angle → amount the turtle turns, pitches, or rolls when commanded (default is 15)
lineWidth → pixel length width of the line (default is 1.0 pixels)
lineIncrement → amount the width of the line is incremented or decremented when commanded (default is 1.0 pixels)
hueChange → amount the hue of the current drawing color is incremented when given the command (default is 10)
Colors
One may specify a new color by a, b, and c by three values separated by commas. If the values are between 0.0 and 1.0, they are interpreted as hue, saturation, and brightness. If outside that range, they will be considered as a standard red, green, blue color scheme ranging from 0 to 225. Blue, for example, is both 0.667, 1, 1 and 0, 0, 255. Concerning built-in colors, the following colors are built into JFLAP. They are case sensitive:
black, blue, brown, cyan, darkGray, darkOliveGreen, darkOliveGreen2, dukeBlue, forestGreen, goldenrod, gray, green, lightGray, magenta, maroon, oliveDrab, orange, orangeRed, pink, purple, red, springGreen, violetRed, white, and yellow
This concludes our brief tutorial on building L-systems. Thanks for reading!