Skip to end of metadata
Go to start of metadata

The purpose of this lab was to familiarize ourselves with L-systems. L-systems model life and other natural phenomena in how they model self-similar growth. Most L-systems use base strings and replacement rules with more than 1 character. For example, a base string could be F=F=F and the rule could be to replace every F with F=F. When the rule is applied once we get F=F=F=F=F=F. Each F in the original string has turned into F=F

We made a python file called lsystem.py that reads a file containing a base string and a replacement algorithm. The file had to follow a specific format, with the words "base" before the base string and "rule" before the replacement algorithm, for the computer to read it.  The replacement algorithm could be encoded with a pair of strings, the first being the string to search for and replace, the second being the replacement. 

Once we had the base string and the rule, we could simply use the replace method on the base string to replace its characters following the replacement algorithm. We used a for loop to iterate the replacement algorithm any number of times. 

l-systems are only interesting when they are used to draw pictures. You can make self-similar pictures resembling plants and fractals by making the characters of the l-string correspond to actions of a pen. For example, F could mean draw a line, and + and - can mean go left and right, respectively. We made python do just that, using a for loop to check each character of an L string, and if the character corresponded to a movement of the turtle pen, it drew that on the screen. 

I used L-systems from the web to draw the following picture: 

each shape is simply a simply a short set of characters made to self replicate using a rule and then read as commands to draw a straight line or turn left or right. I also made the pen change color every time it turned left to make things groovy.

Next I drew a grid to demonstrate the importance of the angle at which the drawing function turns. I also graphed different numbers of iterations of the replacement function to see how l-systems exhibit almost organic growth.

Small angles look the most natural. Once again, just using a string of 5 different characters that could either draw forward, turn left, turn right, save the current position, or return to the current position, with its characters replaced 1,2,or 3 time using a simple rule. Next I drew a garden using several l plant like shapes 

In this project I got to practice how python can read and manipulate text. I also learned how a computer can model life like systems and their complexity by virtue of the speed at which it can calculate. The strings that resulted in the picture above were hundreds of characters long, so to do what the computer did by hand would take a long time. 

Labels