CS151 HW#9
Tara Davidson '10
Write up:
-
A brief description of the task (in your own words): This project also
required working with classes. The LSystem class that I added to works with
L-systems strings. The set function within the LSystem class can set base
strings, rules, iterations, angles, and distance. def setIterations, def
setDistance, def setAngle are functions that can change the default or input
values in the iterations, distance, and angle fields. defDistance and def
getAngle are functions that will return the current values in the distance and
angle fields. def generateString creates a copy of the base string and replaces
characters with a respective rule and returns the new base string. def toString
was already created but prints out key information about the L-system. def
read will read an L-system from a given file name. def write will write the
L-system string to a file in an open directory. Once all the functions in the
LSystem class were filled in, I ran parse.py (which imports the LSystem class)
to test my LSystem class to see the the image parse.py creates - three trees.
The final part of the project was to write a new program - newprogram.py - that
also uses the LSystem class to make a scene with 6 tree-like things in it. For
my newprogram.py I modified 2 tree-like L-systems from ABOP and created one of my own. The image that my
newprogram.py creates is shown below.
-
Explain what the fields are in the LSystem object and the kind of data
each one holds The LSystem object has fields for: baseString, rules,
iterations, angle, and distance. baseString holds a string, rules holds a list,
iterations holds a number, angle holds a number, and distance holds a number.
-
Describe your algorithm for creating the final scene For my final
scene (which I created in newprogram.py) I copied the processString function
from parse.py so that each character in my baseString and rules could be drawn
appropriately. Then I created a main function. In my main function I create a window for the scene to be
created in. I decided I wanted my scene to be drawn fast with turtleTrace set
to False. Then I created 6 tree-like things by setting variables (such as TreeOne, TreeTwo) to LSystem and by modifying L-systems from ABOP
in the set functions. I did this for all six trees.
Then I set a position for my turtle to start at and put the turtle down on the
window. I then drew each tree-like thing by creating a starting position for the
turtle, setting a unique distance for each tree-like thing, and processing
the string for each tree-like thing. I also decided to print out a statement
to indicate that the tree-like thing had been drawn. I ended my main function
by moving the turtle to a position out of the generated scene, (0,0), and by
waiting for the user to click RETURN (so that the window would not disappear
so quickly).
-
Show the generated scene from newprogram.py