I485: Biologically Inspired Computing
Lab 2: Lindenmayer Systems
Summary
- Read Section 7.4 in de Castro's Fundamentals of Natural Computing
- Complete the following 5 problems. Each answer is worth 2 point, for a total of 10 points.
- Attach answers as separate Python files to your submission for 'Assignment 1' in Oncourse
- Assignment is due by 1pm on February 18th
Questions or problems? See my email and office hours information.
The problems:
- Section 7.4 in de Castro describes how an L-system involves rewriting words by iteratively applying a set of productions, starting from a given axiom. The pseudocode for this procedure is provided in Algorithm 7.1.
You need to implement this algorithm as a Python function. Your function parameters should be: an axiom, a sequence of production rules, and the number of iterations to perform rewriting. Then, call this function withaxiom = 'FX', aproduction_set = {'X':'X+YF+','Y':'-FX-Y'}(in Python dictionary notation), and 5 maximum iterations. Print out the result.
- We would like to graph our L-system derivations using Turtle graphics. To get started:
- Be sure you have the TkInter graphing package installed.
- See the Turtle documentation page for a list of possible turtle commands
- Review my simple demonstration of how to use the turtle package. It sets up a turtle pen and uses it draw a simple blue square
For this problem, you will need to:- Write a Python function which takes a character string, and uses it to control a turtle pen. The character
Fshould move the pen forward by a certain distance,-should rotate the pen left by δ degrees,+should rotate the pen right by δ degrees. All other symbols should be ignored. - Graph the word produced by the L-system specified in problem 1, iterated at least 10 times, with δ = 90. Ideally, you will see a fractal called the 'Dragon Curve', famously used to open the chapters in Michael Crichton's Jurassic Park.
- Graph a different L-system axiom and production rule. Pick one either from de Castro's book, the Internet, or of your own invention. Use one that does not employ branching commands.
- To complete our L-system graphing project, we need to implement branching. The rewriting code stays the same,
but our Turtle control needs a couple of additions. In addition to the
F,-, and+commands, we also need to implement:- The
Gcharacter serves as a budding point for branch development in rewriting. For Turtle-purposes, it functions exactly like anFcommand [and]initiate and close a branch, respectively. To initiate a branch, we push the current state of the Turtle (retrieved viaposition()andheading()) onto a stack of states. To close a branch, we pop a state off the top of the stack and use it to restore the position and heading of the turtle pen (viagoto()andsetheading()). Remember to raise the turtle pen before restoring the state, and to lower it afterwards (Hint: useup()anddown()).
- The
- Use the branching L-system code you have created to draw three different types of trees, taking their axioms and productions rules either from the book or the Internet. Remember to alter your angle δ — most likely you will not want 90 degree rotations for trees.
- Use the branching L-system code you have created to draw a whole set of different trees, to be displayed simultaneously. In other words: draw a forest of L-system trees. The trees should be different from one another: you can either program in a set of different L-system axioms and production rules from which you pick randomly, or (if you are really clever) you can generate these by randomly assembling commands. Be sure to randomly vary your δ's within a certain range, so the rotation angles of the trees differ from one another.
More
Acknowledgements
- Lab prepared by Artemy Kolchinsky.
Links
I485/I585 Biologically-inspired Computing

