CS 151: Project #10

Project 10: Unique Trees and Shapes

Main course page


  1. Create a file called tree.py. Import your lsystem3 and shapes modules. Within the file, build a Tree class that makes use of an Lsystem to generate a string to draw. The Tree class should inherit the Shape class, but you'll need to override some of the methods. The methods you'll need to override or create for the Tree class include:
    • def __init__(self, distance=5, color=(0.5, 0.4, 0.3), iterations=3, filename=''): - The init function should call the parent init, store the iterations number in an iterations field, then create an Lsystem object and store it in an lsystem field. If the filename is not empty, the Lsystem should read the file. Lastly, it should copy the Lsystem angle field to the angle field of self.
    • The setAngle function needs not only to set the angle field of self, but also to call the setAngle method of the Lsystem.
    • Create a setIterations accessor for the iterations field of the Tree object.
    • Override the draw method--but keep the same parameter list--so it uses the Lsystem to build the string and then calls the parent draw function.

    Once you've written the tree class, make a test method for the class and try it out.

  2. Create a scene where there are five trees of the same type of stochastic L-system (like systemE or systemF from the lab). Enclose the scene in two concentric boxes so it looks like a painting. You may want to make a rectangle class that uses a different string than the Square class.

    Grab a screen shot of your scene and include it in your writeup.

  3. Create at least three other classes that inherit the Shape class and define different shapes using strings, just like the Square and Triangle classes. One of them should make a filled shape using curly brackets { and } to turn on and off the fill (you'll need to update your transformer to do the right thing). Then make a scene that incorporates all of your different shapes.

    Grab a screen shot of your scene and include it in your writeup.


  1. Use additional symbols to enable the Transformer's drawString function to do more. For example, in ABOP the ! symbol denotes a decrement of the branch diameter (think line width).
  2. Add gravity to your trees so the branches droop towards the ground. You probably want to add some options to your drawString function to enable this effect.
  3. Make your own L-systems.
  4. Make additional shape classes. How would you, for example, make a generic N-gon class?

Code Handin

Hand in your code for this assignment using the Moodle drop box. There will be a drop box for each week's assignment. Hand in your python code file. If there are any specific images required for your system to work, zip them up with your code file.

Please do not place code anywhere public. Do not include it in your writeups on the wiki, for example.


Each of you should create your own wiki page for your writeup. The writeup can be brief, but should include the following components.

  1. A brief abstract (200 words or less) describing the project.
  2. A more detailed description of what you did. This week, focus on the use of a dictionary for storing rules and how you used inheritance to generate the various shape classes.
  3. Include any images or other output your program created. For this project, include screen captures of your scenes.
  4. Describe any extensions you implemented and show results for them.
  5. Give a brief (1 paragraph) description of what you learned.

Colby Wiki

Please put the label cs151s09proj10 on your writeup page (down below the editing window on the edit tab). Please make sure you type the label exactly as given above.