-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline.py
34 lines (28 loc) · 953 Bytes
/
line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from tkinter import Canvas
from point import Point
from utils import LINE_COLOR
class Line:
"""
Receive two Point classes to draw a line between them.
"""
def __init__(self, point_A: Point, point_B: Point) -> None:
self.point_A = point_A
self.point_B = point_B
def draw(self, canvas: Canvas, fill_color: str = LINE_COLOR) -> None:
"""
Draw a line between two Point's in a Canvas.
canvas: TK Canvas
fill_color: TK Color (name of the color or HEX #rrggbb value)
"""
canvas.create_line(
self.point_A.x,
self.point_A.y,
self.point_B.x,
self.point_B.y,
fill=fill_color,
width=2
)
def __repr__(self) -> str:
return f"Line({repr(self.point_A)}, {repr(self.point_B)})"
def __str__(self) -> str:
return f"Line between: ({str(self.point_A)}) and ({str(self.point_B)})"