Project 8: More Trees
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.)
In order to place trees and such, you need some functions that will
move the turtle around. Create the following three methods in your
- 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.
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.
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.
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.
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.
- Have each tree exhibit some variation by modifying the distance or angle arguments to drawString.
- Add leaves, berries, or color to your trees by adding symbols to the rules and cases to your interpreter. For each new symbol, you will need another elif case in your drawString function.
- Get fancy with required images 2 or 3.
- Make more L-systems.
- Demonstrate that you can create other kinds of shapes by passing strings to the interpreter's drawString function.
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.
In general, your writeup should follow the outline below.
- A brief summary of the task, in your own words. This should be no more than a few sentences. Give the reader context and identify the key purpose of the assignment.
- A description of your solution to the tasks, including any images you created. This should be a description of the form and functionality of your final code. You may want to incorporate code snippets in your description to point out relevant features. Note any unique computational solutions you developed.
- A description of any extensions you undertook, including images demonstrating those extensions. If you added any modules, functions, or other design components, note their structure and the algorithms you used.
- A brief description (1-3 sentences) of what you learned.
- Don't forget to label your writeup so that it appears in the listing on the main wiki page for the course. For this lab, use cs151s10proj8