from math import * # A Point object represents an integer x/y location. class Point: # Constructs a new point at the given x/y location. def __init__(self, x, y): self.x = x self.y = y # Sets this point's location to the given coordinates. def set_location(self, x, y): self.x = x self.y = y # Shifts this point's location by the given amounts. def translate(self, dx, dy): self.x += dx self.y += dy # Draws this point onto a drawing panel in the given color (default black). def draw(self, panel, color="black"): panel.canvas.create_oval(self.x, self.y, self.x + 3, self.y + 3, fill=color, outline=color) panel.canvas.create_text(self.x, self.y, text=str(self), anchor="sw", fill=color) # Returns how far this point is away from the given other point. def distance(self, other): dx = self.x - other.x dy = self.y - other.y return sqrt(dx * dx + dy * dy) # Returns how far this point is away from the origin (0, 0). def distance_from_origin(self): return self.distance(Point(0, 0)) # Returns a text representation of this point, such as "(5, -3)". def __str__(self): return "(" + str(self.x) + ", " + str(self.y) + ")"