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:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
"""The linesegment module defines the class line_segment."""
|
||||
"""The linesegment module defines the class LineSegment."""
|
||||
|
||||
import random
|
||||
import point
|
||||
@@ -63,14 +63,19 @@ class LineSegment:
|
||||
def __str__(self):
|
||||
"""Return the line segment values as string."""
|
||||
return self.__startpoint.str() + "-->" + self.__endpoint.str()
|
||||
def draw(self):
|
||||
"""TODO: Draw the line segment in a canvas."""
|
||||
def draw(self, canvas, width, height, max_x, max_y, color="#000000"):
|
||||
"""Draw the line segment in a canvas."""
|
||||
from_x, from_y = self.__startpoint.draw(canvas, width, height, max_x, max_y, color)
|
||||
to_x, to_y = self.__endpoint.draw(canvas, width, height, max_x, max_y, color)
|
||||
|
||||
canvas.create_line(from_x, from_y, to_x, to_y, fill=color)
|
||||
|
||||
|
||||
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"""
|
||||
seg = LineSegment(point.Point(random.randint(min_x, max_x), random.randint(min_y, max_y)), \
|
||||
point.Point(random.randint(min_x, max_x), random.randint(min_y, max_y)))
|
||||
while ls.get_startpoint().get_x() == ls.get_endpoint().get_x():
|
||||
while seg.get_startpoint().get_x() == seg.get_endpoint().get_x():
|
||||
seg = LineSegment(point.Point(random.randint(min_x, max_x), random.randint(min_y, max_y)), \
|
||||
point.Point(random.randint(min_x, max_x), random.randint(min_y, max_y)))
|
||||
return seg
|
||||
|
||||
Reference in New Issue
Block a user