I485: Biologically Inspired Computing

Lab 2: Lindenmayer Systems

Topics

Assignment #1

  1. Read Section 7.4 in de Castro's Fundamentals of Natural Computing
  2. Complete the following 4 problems, worth a total of 10 points. Points for each question are also shown.
  3. Attach answers as separate Python files to your submission for 'Assignment 1' in Oncourse. Summarize your answers in a separate document including figures, if any.
  4. Assignment is due by 11am on September 29th

    Questions or problems? See my email and office hours information.


The problems:


  1. [2 points] Generating words: Section 7.4 in de Castro describes how an L-system re-writes words by iteratively applying a set of production rules, 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 rewriting iterations. Then, call this function with axiom = 'FX', a production_set = {'X':'X+YF','Y':'FX-Y'} (in Python dictionary notation), and 5 maximum iterations. Print out the result. Create a new equivalent rule set by doing a small rearrangement to the above production rule set in order to get the same output (half a point for answering this subquestion).
  2. [2 points] Drawing the words: Using turtle, graph the words generated in problem 1, at each iteration. 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 F should 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. Remember that the turtle module in Python will not automatically recognize these symbols---you need to implement them.
    • Graph the word produced by the L-system specified in problem 1, iterated at least 10 times, with δ = 90. Your picture should look like the "Dragon curve", famously used to open the chapters in Michael Crichton's Jurassic Park. Capture the picture generated in the last iteration and display it in your solution summary (in addition to the python file).
    • 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.

  3. [2 points] Drawing with branching: Lindenmayer introduced the branching symbols '[' and ']' in production rules, to be able to draw plants more effectively. Draw the two different "plants" defined by the following L-Systems (1 point each):
    • L-System 1: Axiom = F; F = F[+F][-F]F
    • L-System 2: Axiom = B; B = F[-B] [+ B]; F = FF
    Note: because these L-Systems include branching, you need to extend the program you developed for the previous questions to also include the following:
    • [ and ] initiate and close a branch, respectively. To initiate a branch, we push the current state of the Turtle (retrieved via position() and heading()) 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 (via goto() and setheading() ). Remember to raise the turtle pen before restoring the state, and to lower it afterwards (Hint: use up() and down() ).
    • The B character (in L-System 2) serves as a budding point for branch development in rewriting. Your program can simply ignore that character to draw the branching plant, and simply interpret the standard turtle codes F, +, - (though you can optionally draw a distinct element for B ).

  4. [4 points] Drawing variety: 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 that the rotation angles of the trees differ from one another.

More

Acknowledgements

Links

All Class Labs

I485/I585 Biologically-inspired Computing

Life Inspired




For more information contact Santosh Manicka or Luis Rocha.
Last Modified: September 23, 2011.