Add draw implementation for existing classes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
14
point.py
14
point.py
@@ -23,15 +23,23 @@ class Point():
|
||||
return self.__y
|
||||
def __eq__(self, other):
|
||||
"""Returns True if the points coordinates are the same, else returns False"""
|
||||
return self.get_x() == other.get_x() and self.get_y() == other.get_y()
|
||||
if other:
|
||||
return self.get_x() == other.get_x() and self.get_y() == other.get_y()
|
||||
return False
|
||||
def __ne__(self, other):
|
||||
"""Returns True if the points coordinates are the different, else returns False"""
|
||||
return self.get_x() != other.get_x() or self.get_y() != other.get_y()
|
||||
def __str__(self):
|
||||
"""Returns the coordinates as a string"""
|
||||
return "(" + str(round(self.get_x(), 2)) + "/" + str(round(self.get_y(), 2)) + ")"
|
||||
def draw(self):
|
||||
"""TODO: Draw the point in a canvas"""
|
||||
def draw(self, canvas, width, height, max_x, max_y, color="#000000", radius=1):
|
||||
"""Draw the point in a canvas"""
|
||||
center_x = self.get_x() * (width / max_x)
|
||||
center_y = height - (self.get_y() * (height / max_y))
|
||||
if center_x <= width and center_y <= height:
|
||||
canvas.create_oval(center_x - radius, center_y - radius, \
|
||||
center_x + radius, center_y + radius, fill=color)
|
||||
return center_x, center_y
|
||||
|
||||
def get_random(min_x=0, max_x=100, min_y=0, max_y=100):
|
||||
"""Set the point to a random place inside the boundaries"""
|
||||
|
||||
Reference in New Issue
Block a user