L-systems (Lyndenmayer systems) are a compact way to describe iterative graphics using turtle analogy. An L-system is created by starting with an axiom , such as a line segment, and one or more production rules, which are segments such as: "replace every line segment with a left turn, a line segment, a right turn, another segment..". When this system is iterated several times, the result is often a complicated fractal curve
A easy way to represent the L-systems is to write the axiom as a sequence
of characters, such as F, and the production rules as replacement
rules of the form: F->F+F--F+F. We then carry out the string replacements
(in parallel) as many times as desired. For example, when we iterate the
axiom and the production rule just described we get:
F+F--F+F first time
F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F the second time
and so on.
After the desired number of iterations has been carried out, we render the L-system string using the turtle analogy. A typical interpretation of our string is that an F is an instruction to draw a line segment one unit in the current direction, a + is an instruction to rotate the current direction one angular unit clockwise, and a - is an instruction to rotate the current direction counter clockwise. In our example, if we assume that one angular unit is 60 degrees we get exactly the Koch's fractal (first choice in my applet)
As special problems encountered I can present the decision of what structure to use for storing the L-system string. I chose the linked list hoping that it will accomodate larger dimensions. Therefore, I had to implement the list and also the method for replacing in parallel) of the axiom with the replacement string. I hope you will appreciate the way I did it and will also acknowledge that the task was beyond the initial requirements. Enjoy!
The list of files:
MyPanel.java The applet that you see
FractalCanvas.java The canvas for drawing the fractals
LFractal.java The class representing the Lyndenmayer fractals
CharList.java The class written for dealing with the L-system string
HelpFrame.java The class for the frame
Disclaimer: As far as I know, apart from the L-System fractal description (presented above) that belongs mainly to Robert M. Dickau, no other parts are taken form anywhere. Although there are many java implementations of the fractals that can be found on the web (just try a search on fractals), the entire code is written by me and the design of the applet (and the idea of using lists) belongs also to me.
by Stefan Alexandru Robila