This is an individual assignment.
Many complicated movie scenes that you see involve lots of individually generated objects, all assembled together on one screen. A computer generated movie scene of a city (such as in the Spiderman movies, for example) involves 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. (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. Specifically, it should have the
following methods:
Part 1
a constructor
setHeight(h)
(sets the height of the building to h
)
setWidth(w)
(sets the width of the building to w
)
setColor(col)
(sets the fill color of the building to col
. The outline
should always be black.)
setHorizontalLocation(loc)
(sets how many pixels over from the left of the canvas the building
begins)
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.)
Part 2
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 the horizontal location to a random value from 0 to maxLoc
,
inclusive)
setColorRandom()
(sets the building fill color randomly)
area()
(returns the area of the building (width * height). This is used for
determining real-estate taxes.)
You should add on your own any other instance variables that you need.
Draw your building by doing what you can to make a rectangle look building-like. 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.
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
.
When you are all done with Part 2, test your code against
the skyline.py that I provide. If you have
built your Building
class correctly,
this skyline.py
program should generate an awesome
skyline for you to look at.
Note that even though skyline.py doesn't use all of the methods from part 1, your final submission for part 2 should have all of the methods from both part 1 and part 2 above.
Good luck, and have fun! Remember that lab assistants and prefects are available to help out if you need it.