''' city4.py Jeff Ondich, 10/23/09 Putting the Building class through some paces, round 4. ''' import sys import time import random from graphics import * from building import Building debugging = True if len(sys.argv) != 2 or not sys.argv[1].isdigit(): print 'Usage: %s numberOfBuildings' % sys.argv[0] exit() cityWidth = 800 cityHeight = 500 window = GraphWin('City', cityWidth, cityHeight) # Put lots of random buildings in a list. if debugging: print '[Debug] Creating buildings.' buildingList = [] numberOfBuildings = int(sys.argv[1]) for k in range(numberOfBuildings): left = random.randint(-10, cityWidth) bottom = cityHeight - 10 width = random.randint(75, 250) height = random.randint(100, cityHeight - 20) color = color_rgb(random.randint(0, 255),random.randint(0, 255),random.randint(0, 255)) b = Building(left, bottom, width, height) b.setColor(color) buildingList.append(b) # Draw the buildings. if debugging: print '[Debug] Drawing buildings.' for b in buildingList: b.draw(window) # Start turning on office lights. if debugging: print '[Debug] Turn on office lights.' for k in range(40): b = random.choice(buildingList) b.turnOnRandomLight() time.sleep(0.2) # Wait while people work too much. if debugging: print '[Debug] Working...' time.sleep(3.0) # Turn the lights back off. if debugging: print '[Debug] Time to go home.' for b in buildingList: b.turnOffLights() response = raw_input('Hit Enter to quit')