CS151 HW#2

Write up:

This task required going beyond what we learned in lab last week by not only using turtle graphics to create squares, but to create whole scenes of buildings. I started by creating a function for a building of my own design and of a certain size. After that, I changed the function so that my building could be drawn at any scale, in any location, and copied multiple times. I created two scenes: scene1.py and scene2.py. In scene1.py, my building is drawn so that the longest side (it's height) is 50 pixels and an identical building half the size, 25 pixels, is drawn to the right of the first building. In scene2.py, my building is drawn 5 times to make a cityscape. In my scene I chose to have all my buildings on the same horzontal line, but all different sizes: 30 pixels, 50 pixels, 75 pixels, 100 pixels, and 125 pixels.

I began by first only parameterizing my building function with one variable, dx. dx was the height, or longest side of my building. I represented every other length of my building in terms of dx. Because every other length needed to design my building was smaller than dx I used decimals multiplied with dx to express their relative sizes. When I got to designing scene1.py I needed more parameters because my second building's coordinates needed to be changed so that my second building didn't overlap my first building. Instead of my function being: building(dx), I redefined my building function as: building(dx, x, y). Within my building function I used other variables such as x0 and y0 to describe window locations, but dx, x, and y remained my only input parameters because x0 and y0 were expressed in terms of dx, x, and y. For both my scenes my turtle started drawing at the origin (0,0). In scene1.py, my turtle started drawing the second building at (100, 0). In scene2.py, the bottom left hand corners of my buildings started at (0,0), (70,0), (-75,0), (125, 0), and (-100, 0).

Picture of scene1.py

Picture of scene2.py