""" A simple GUI to draw 3 rectangles and display statistics on each. Author: Curt Clifton, David Mutchler, and TODO: 1. YOUR-NAME-HERE. """ from zellegraphics import * #@UnusedWildImport # Nearly constants window_title = "Eat three rectangles a day!" window_width = 800 window_height = 400 rectangle_count = 3 initial_prompt = "Click once to set the first corner " + \ "and again to set the opposite corner" final_prompt = "Click one more time to exit" initial_prompt_color = 'blue' final_prompt_color = 'red' def main(): # window on which we will draw things window = GraphWin(window_title, window_width, window_height) # draw a prompt message at bottom of window, centered prompt = Text(Point(window_width / 2, window_height - 5), initial_prompt) prompt.setTextColor(initial_prompt_color) prompt.draw(window) # get rectangles from the user, displaying their properties for k in range(rectangle_count): #@UnusedVariable rectangle = get_rectangle_from_user(window) display_rectangle_statistics(rectangle, window) # change the prompt message at bottom of window and exit on click prompt.setText(final_prompt) prompt.setTextColor(final_prompt_color) window.getMouse() # Wait for click, then exit window.close() def get_rectangle_from_user(window): """ Get and return a rectangle from the user. The user should click twice on the given window to establish the corners of the rectangle. """ p1 = window.getMouse() # get first corner from user, then draw it p1.draw(window) p2 = window.getMouse() # get second corner from user, then draw rectangle p1.undraw() rectangle = Rectangle(p1, p2) rectangle.draw(window) return rectangle def display_rectangle_statistics(rectangle, window): """ On the given window, display statistics for the given rectangle, as follows. At two opposite corners of the rectangle, display the coordinates of the corners; and in the center of the rectangle, display the rectangle's area and perimeter. """ # TODO: 2. Make the location of the constructed message be the rectangle's center. location = Point(200, 200) text = statistics(rectangle) message = Text(location, str(text)) message.draw(window) # TODO: 3. At each of the corners used to construct the rectangle, # display the corner's X and Y coordinates def statistics(rectangle): """ Return (as a 2-tuple) the area and perimeter of the given rectangle """ # TODO: 4. Implement this function. main()