Homework 2

Turtle Graphics

Description:

The object of this project was to become efficient with turtle graphics by learning to define and parameterize functions. We were required to draw two buildings parametrized by a single variable, from which we were required to draw a "city" with many buildings and other features that we desired. We were required to use python to call our saved 'scene1' and 'scene2' and capture the resulting images.

I started by creating a python file cityshapes.py in which I defined a function building(dx). This was a preliminary function that was no more than a rectangle parameterized by (dx). After testing the function, I created a function called frame into which I transfered building's actions. I then created a function called square which drew a simple square using (dx) to parameterize the square. I then created a function called window which used a formula to determine the appropriate number of windows and the spacing in between them to put on the building. The function square was then called into window within a loop with a value for (dx). This function was then called into building, resulting in an appropriate number of windows being drawn on each building. In addition, I created a door function that I decided to define a separate set of commands in order to create the proper appearance of a 'double door' like one would see on a building. This was also passed into the building function. I needed to add variables to the building function to reflect the variables required for the frame, window, and door functions respectively. I added the following variables: (dx,x0,y0,red,green,blue,dofill). this allowed for colors and fill options to be incorporated, as well as my starting values (x0=-300,y0=-250) to be included in order to complete certain functions. After fine-tuning my general city, I decided to add the concrete ground to make the buildings look slightly more realistic. I used a simple function sidewalk, with hard coded values to ensure the ground would extend the entire length of the picture in the correct position. I played with the thought of having other parameters other than (dx) to change aspects of the buildings, creating an entire new program named 'bigcity.py' complete with if<> elif<> statements to parameterize 5 different building shapes with similar deviations from the window function. This program had continuous bugs however, so I decided that with the amount of familiarity I have acquired with python, I would not be able to properly code the entire program efficiently. I decided to incorporate another idea I had from 'bigcity.py' into my 'scene2'. After drawing a large square slightly larger than the sky and filling it black (to give the appearance of night) I created a star function (which I then compared to the tree example to verify) and then put this into a random loop that drew stars of varying size and location in the sky. To conclude my project, I decided to create one more function- antenna, to add an antenna on select buildings. Within this function I found it easier to create a separate small function to draw the light on top, which I called 'light'. Antenna used parameters from the building function to correctly orient the cursor to draw an antenna of scaled length directly in the middle on top of a building, and then draw the light on top of that. All in all, I was satisifed with my program(not to mention relieved that I didn't have to wait for the turtle to draw the entire scene any more). As a final addition for astetic reasons, I decided to relocate the cursor slightly off the bottom left corner of the screen, as not to interfere with the final picture.

Picture of 'scene1':

Picture of 'scene2':