''' city.py Feb 14, 2011 Written by Jeff Ondich and friends to illustrate classes. ''' import random import time from building import * from car import * from graphics import * # Initialize city window windowHeight = 500 windowWidth = 700 windowTitle = 'City' backgroundColor = color_rgb(255, 255, 255) window = GraphWin(windowTitle, windowWidth, windowHeight) window.setBackground(backgroundColor) # Create the buildings buildings = [] for k in range(20): newBuildingColor = color_rgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) newBuildingLeft = random.randint(-10, windowWidth - 40) newBuildingHeight = random.randint(100, 350) newBuildingWidth = random.randint(50, 150) newBuilding = Building(newBuildingLeft, newBuildingWidth, newBuildingHeight, newBuildingColor) buildings.append(newBuilding) # Draw the buildings for building in buildings: building.draw(window) # Create the cars cars = [] for k in range(5): color = color_rgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) left = random.randint(-10, windowWidth - 40) newCar = Car(left, color) cars.append(newCar) # Draw the cars for car in cars: car.draw(window) while True: time.sleep(0.10) for car in cars: car.move(5) s = raw_input('Hit Enter to quit')