CS151 HW#6
Tara Davidson '10
Write up:
-
A brief description of the task (in your own words): This task required
using what we've learned about the graphics package over the past week and a half
to create another city scene, this time without turtle graphics and just by
using the Zelle graphics package. To create my city, I created a handful of functions.
I had a function for my first type of building, my second type of building, my
highway, my traffic light, and then functions that could draw my objects (buildings,
highway, traffic light...), move my objects, clone my objects, and a function
that could animate the windows of my buildings. Functions for my buildings, highway,
and traffic light took at most the parameters of: the window, the x location,
the y location, and dx (the footprint of my building). Having only these parameters
allows my city to have objects drawn anywhere in a window and scaled to any size.
I also created a file, cityscene.py that called these functions to create a specific
city scene to my choosing. The functions I just mention, I created in city2.py and
they were never called in city2.py. In my scenecity.py I created
a city with 6 buildings (3 of each type), a highway at the foot of the buildings,
and a traffic light. In my scene I used these Zelle graphics objects: a Point,
a Rectangle, a Circle, and a Line. I animated all the windows of my buildings so
that the windows flash yellow instead of dark blue on a random sleep timer. 20
images of my scene is below in an animated gif.
-
The image of your scene, preferably as an animated gif
-
A description of how you took advantage of loops, conditions, parameterization,
and randomization in your scene to reduce the amount of code you had to write
I took advantage of only having (at most) 4 input parameters so that my objects
could change. By having dx as a parameter
another user could choose to scale my buildings differently. By having x0 and y0
as parameters, another user could choose to place my objects in different locations.
I used loops for my windows in my buildings so that I didn't have to write code
for every single window in my city. I did this by having a loop for every story
in the building and having an inner loop for every window in that story. I also
used loops for my move, draw, and clone functions. These functions would
take the string bldg that I appended all my objects' characteristics in and then for
every character in that string they would move, draw, or clone them. For my function
that animated my windows I used conditions and randomization. For the windows in my bldg string, I assigned
the windows a random number and if that random number was < .5 they'd turn yellow,
if not they'd stay dark blue.
-
Identify at least one instance of each Zelle graphics object in your scene
I used Rectangle for the outline of my building, I used Circle for my traffic light's
red light, I used Line for my highway's yellow line, and I used points to create
my Rectangles, Circles, and Lines.