Skyline Lab

Table of Contents

This is a pair programming assignment. If you are working in a pair, this means that you and your partner should be doing the entirety of this assignment side-by-side, on a single computer, where one person is "driving" and the other is "navigating." Set a timer to swap every 15 minutes. You can choose your favorite from this online timer page. Make sure your sound volume is audible, but not so loud to disturb the people around you.

If you are working in a pair, only one of you needs to submit your work via Moodle. That said, you should both have a copy of your work in case you want it someday, so make sure that both of you have copies of it; you can email it or use some other mechanism to transfer it.

We will use anonymous grading on Moodle, which means that the grader won't see your name until after the grading is done. This is an easy way to help add an extra element of fairness to the grading. Therefore, make sure your name doesn't appear on your actual submission. When you submit via Moodle, it will know you are. Thanks!

1 Overview

Many complicated movie scenes that you see involve lots of individually generated objects, all assembled together on one screen. The Lord of the Rings movies famously used simulations where each fighter in a battle was a computer generated object. Similarly, a computer generated movie scenes of a city (such as in many of the Marvel superhero movies, for example) involve superimposing a number of buildings of different shapes and sizes. For this assignment, you will create a city by drawing a number of buildings of varied sizes.

Create a directory named skyline to store your work, then copy into it graphics.py (which you can find on our Moodle site near our easlier assignments). (For part 2, copy your directory and all code within to another directory called skyline2; that way, you don't clobber your first submission after you turn it in.) Create a class called Building (in a file called building.py) to represent a building in a city.

2 Methods you will write

The Building class should have the following methods:

  • a constructor
  • setHeightRandom(maxHeight)

    sets the height to a random value from 0 to maxHeight, inclusive

  • setWidthRandom(maxWidth)

    sets the height to a random value from 0 to maxWidth, inclusive

  • setLocationRandom(maxLoc)

    sets how many pixels over from the left of the canvas the building begins to a random value from 0 to maxLoc, not including maxLoc

  • setColorRandom()

    sets the building fill color randomly. The outline should always be black.

  • area()

    returns the area of the building (width * height). This is used for determining real-estate taxes.

  • draw(graphicsWindow, windowHeight)

    given a graphics window and its height, draw the building. The reason that you need the the height of the canvas to figure out where to start drawing the top of the building. If buildings extended down from the top of the canvas, i.e. the picture were upside down, this wouldn't be necessary. For purposes of this assignment, you can draw the building as a rectangle.

3 Some more details and advice

Test your code as you go along. Put your main function in a separate file called skyline.py, and include the code

from building import *

at the top of it. As you write methods in your Building class, test them in main in skyline.py. I strongly recommend that you seed your random number generator so that you get the same behavior every time you run your program. It's much easier to debug that way.

When you are all done, test your code against the skyline.py that I provide. If you have built your Building class correctly, my skyline.py program should generate an awesome skyline for you to look at.

4 The last point

If you get all of the methods implemented and working, go back and add what you can to make your rectangle look building-like. You might add an antenna to the top of the building whose height is proportional to the rest of the building. Draw windows running down and across the buildings. You don't need to go crazy making the width of the windows correct or anything like that: some attempt at making some kind of repeated pattern of windows should do the trick. Of course, feel free to get as fancy as you like after you get everything else working.

5 Submit your work

When finished, zip up your code and submit your work through Moodle.

Good luck, and have fun!

Author: Dave Musicant

Emacs 24.5.1 (Org mode 8.2.10)

Validate