""" example-baseball_diamond.py A example to discuss in class : interactive creation of a graphics diamond """ from graphics import * class DiamondWindow: def __init__(self): self.color3 = "blue3" self.window = GraphWin("Can you draw a baseball diamond?", 400, 400) self.script_1 = Text(Point(125, 375), "click four points") self.script_1.draw(self.window) script_2 = Text(Point(125, 365), "GO TIGERS!") script_2.setFace('times roman') script_2.setStyle('bold italic') script_2.setTextColor(self.color2) script_2.draw(self.window) line = Line(Point(0, 350), Point(400, 350)) line.setOutline(self.color3) line.draw(self.window) def change_text(self): self.script_1.setText("click to exit") def getMouse(): return self.window.getMouse() class Diamond: def __init__(self, window): self.window = window self.color = "grey" self.color2 = "orange2" self.radius = 5 self.get_points_and_draw() def draw_diamonds(self): # make individual diamonds for i in [0,1,2,3]: self.draw_diamond(i) def draw_diamond(self, point_index): point = points[point_index] diamond = Circle(point, self.radius) diamond.setFill(self.color2) diamond.setOutline(self.color3) diamond.draw(self.window) def get_points_and_draw(self): self.points = [None, None, None, None] for i in [0, 1, 2, 3]: self.points[i] = window.getMouse() self.points[i].draw(self.window) self.poly = Polygon(points[0], points[1], points[2], points[3]) self.poly.setFill(self.color) self.poly.draw() self.draw_diamonds() class main(): window = DiamondWindow() diamond = Diamond(window) window.change_text() # change to 'click to exit' window.getMouse() # wait for user to click