CS 151: Project #8

Project 8: More Trees

Main course page

As with last week, the assignment is to bring together the lsystem and interpreter classes to make a scene that consists of fractal shapes and trees. Your top-level program will include both the lsystem and interpreter modules. Unlike last week, however, your scene.py may not include the turtle module or make any calls to turtle commands. If you want to draw something, you have to pass a string to the interpreter drawString function. There will be no exceptions to that rule. (Note that you may, in fact, attach arbitrary meaning to any character not used by an L-system grammar.)


Tasks

  1. In order to place trees and such, you need some functions that will move the turtle around. Create the following three methods in your interpreter class.
    • def place(self, xpos, ypos, angle=None): - the method should pick up the pen, place the turtle at location (xpos, ypos), orient the turtle if the angle argument is not None, and then put down the pen.
    • def orient(self, angle): - the method should set the turtle's heading to the given angle.
    • def goto(self, xpos, ypos): - the method should pick up the turtle, send the turtle to (xpos, ypos) and then put the pen down.
  2. In the Lsystem class create a method def __str__(self) that returns a nicely formatted string that might look like the following. The __str__ function gets called automatically when an object is printed out. It's also called to implement casting an object to a string using str(thing).

    base X
    rule X -> F-[[X]+X]+F[+FX]-Xl
    rule F -> FF
    

    In the test main function the line print lsys should now print out your nicely formatted string instead of the generic class instance string.

  3. Create a file task1.py. Have the file import lsystem and interpreter (the new versions). Make a function scene that creates a simple image with at least two different multi-rule L-systems. See if you can put the base string and rule below the corresponding picture.

    This is required image 1.

  4. Create a file task2.py. Make a forest (randomized or not) with at least a half-dozen trees of at least 3 types. Create a separate L-system object for each tree type. At least one of the trees must be a multi-rule L-system.

    This is required image 2.

  5. Make new L-system. It can be a variation on one of the ones from the ABOP book or one you create on your own. If it's a variation, include both the original and your variant in your writeup. (The difference does not have to be large.)

    In the file task3.py, create a scene function that makes an image of your L-system after 2, 3, and 4 iterations.

    This is required image 3.


Extensions


Writeup

Make a new wiki page for your assignment. Give the page a useful title using English words. Put the label cs151s10proj8 in the label field at the bottom of the page. Each of you needs to make your own writeup.

In addition to making the wiki page writeup, put the python files you wrote on the Academics server in your handin directory.

Colby Wiki

In general, your writeup should follow the outline below.