''' cartester.py Jeff Ondich, 10 February 2010 This program tests the Car class in car.py by generating some random Car objects and letting them drive away. ''' import random from car import * from graphics import * # Open a graphics window. windowWidth = 600 windowHeight = 400 window = GraphWin('The open road', windowWidth, windowHeight) # Generate a collection of Car objects with random properties. carList = [] for k in range(5): y = random.randint(20, windowHeight - 20) width = random.randint(50, 200) x = random.randint(width + 1, windowWidth - width - 1) height = random.randint(30, 100) velocity = random.randint(-20, 20) color = color_rgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) car = Car(x, y, width, height, color, velocity) car.draw(window) carList.append(car) # Drive the cars until the user terminates the program. print 'Hit Ctrl-C to quit' while True: time.sleep(0.1) for car in carList: car.step() if car.x + car.width >= windowWidth: car.undraw() car.reverseDirection() car.draw(window)