# CSE 142, Summer 2008 (Kim Todd) # This program draws a car and a stop sign on the DrawingPanel # using octagons as their bodies. from drawingpanel import * # Draws an octagon figure with the given position, size, and fill color. def octagon(panel, x, y, width, height, fill_color="black"): panel.canvas.create_polygon(x, y + 10, # 1 x + 10, y, # 2 x + width - 10, y, # 3 x + width, y + 10, # 4 x + width, y + height - 10, # 5 x + width - 10, y + height, # 6 x + 10, y + height, # 7 x, y + height - 10, # 8 fill=fill_color, outline="black") # Draws a car figure with the given position and size. def car(panel, x, y, size): octagon(panel, x, y, size, size / 2) panel.canvas.create_oval(x + size / 10, y + size * 2 / 5, x + size * 3 / 10, y + size * 3 / 5, fill="yellow", outline="blue") panel.canvas.create_oval(x + size * 7 / 10, y + size * 2 / 5, x + size * 9 / 10, y + size * 3 / 5, fill="yellow", outline="blue") panel.canvas.create_rectangle(x + size * 7 / 10, y + size / 10, x + size, y + size * 3 / 10, fill="cyan", outline="cyan") # main panel = DrawingPanel(250, 120) panel.canvas["bg"] = "gray" # car car(panel, 10, 10, 100) # stop sign octagon(panel, 150, 10, 40, 40, "red") panel.canvas.create_rectangle(165, 50, 175, 80, fill="brown") panel.mainloop()