Task:
Cityscape Take 2 was intended to familiarize us with the Zelle graphics package. In order to do so, we were required to create another cityscape using the Zelle graphics objects. The drawing process was expedited by using loops, conditions, and parameterization. We were required to create a file that contained the code for two building types along with any coding for features for each building. This program was called city2.py and it made use of loops within the building functions to reduce the amount of code needed to draw features such as windows. This was then called into a cityscape program and the demotest program similar to the graphics package.The cityscape and demotest programs then used the graphics package in combination with the city2 functions to create scenes with the two building types and animation. These programs themselves made use of the Zelle graphics objects along with the time package for the animations. Such relatively simple transfers from the Turtle graphics package to the Zelle graphics package allowed for greater simplicity in the program code.
Image from demotest.py:
Image from cityscape.py:
Using Loops, Conditions, and Parameterization Within the Scene:
I took advantage of many coding options within my programs. Within city2.py, I was sure to use nested for loops to draw the windows on the buildings. In addition, I used parameterization throughout the building functions including drawing doors and windows. This allows for one parameter to be changed and all the items that are affected change in proportion to the parameter. Conditions were also incorporated into city2.py when determining how many windows to draw on each building. I also took advantage of loops, conditions, and paremeterization within cityscape.py. Loops were used to draw multiple buildings and within the animation. Conditions were used within the animation to determine if the animation should continue or if the entire screen should be closed due to a mouse click. Once again, parameterization was used to draw the buildings as well as to orient the objects within the window. In using these elements within the programs, they provided the ability to draw an entire scene with relatively little code. Additionally, they allowed the appearance of the scene to be easily manipulated by changing the parameters.
Zelle Graphics Objects Within the Scene:
There are many duplicates of the Zelle graphics objects within my scene: in particular, the rectangle. The rectangle appears in the outline of the building, the windows, the door, the background of the image, the ground, and the roads. In order to draw the rectangles, I made use of points and point methods to use previously defined points. I also used lines to draw the street lines on the roads. In conjunction with the rectangles and lines, I used generic methods such as setFill() and draw to add color and to draw() the figures in the desired location. I also used the undraw() and draw() methods within my animation to give the appearance of movement.
Explanation of Extension:
As an extension, and due to common sense, I used loops whenever possible to save coding time. As mentioned previously, these were found in the window drawing and animation. I also adjusted the appearance of the window arrangement on each building based on the given parameter dx of each building. This assured that there would not be too many windows drawn and that they would be drawn in a predictable manner on each building. It was based on a simple conditional that examined dx, or the width of the building, and determined the appropriate number of windows to draw in each row. The same holds true for the number of windows per column based upon a manipulation of dx.