''' city.py Jeff Ondich & friends 26 October 2018 ''' import random from graphics import * from car import * from building import * def get_random_building_color(): # This is the night-time color theme red = random.randint(0, 100) green = random.randint(0, 100) blue = random.randint(0, 180) return color_rgb(red, green, blue) def get_random_car_color(): # Any color will be fine red = random.randint(0, 255) green = random.randint(0, 255) blue = random.randint(0, 255) return color_rgb(red, green, blue) def get_random_building(window_width, window_height): color = get_random_building_color() height_of_greenspace = window_height // 4 width = random.randint(60, window_width // 5) height = random.randint((window_height - height_of_greenspace) // 3, window_height - height_of_greenspace - 20) left = random.randint(0, window_width - 10) top = window_height - height_of_greenspace - height building = Building(left, top, width, height, color) return building def get_random_car(window_width, window_height): color = get_random_car_color() height_of_greenspace = window_height // 4 width = min(window_width // 25, height_of_greenspace // 3) height = width / 1.62 # golden ratio cars! left = random.randint(10, window_width - 10) top = window_height - height_of_greenspace + height car = Car(left, top, width, height, color) return car def main(): window_width = 1000 window_height = 600 window = GraphWin('City', window_width, window_height) for k in range(20): building = get_random_building(window_width, window_height) building.draw(window) for k in range(5): car = get_random_car(window_width, window_height) car.draw(window) input('Hit Enter to quit') main()