-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (50 loc) · 1.76 KB
/
main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import annotations
import turtle
class Point():
def __init__(self,x:float = None, y:float = None, color = 'green') -> None:
self.x = x
self.y = y
self.t = turtle.Turtle()
self.t.color(color)
self.t.goto(self.x,self.y)
self.t.shape('circle')
self.t.up()
def pos(self) -> tuple:
return self.x, self.y
def __str__(self) -> str: return f"{self.x}, {self.y}"
def __mul__(self,divisor):
return Point(self.x / divisor, self.y / divisor)
def coords(self) -> list: return [self.x,self.y]
def setX(self,newx): self.x = newx
def setY(self,newy): self.y = newy
def getX(self): return self.x
def gety(self): return self.y
def updateLocation(self):
self.t.goto(self.x,self.y)
def getMidpointBewteen(self, other:Point) -> Point:
"""returns a Point who's location is the midpoint between self and other
Args:
other (Point): other point
Returns:
Point: Midpoint
"""
return Point((self.x + other.y) / 2, (self.y + other.y) / 2)
class Line:
def __init__(self, **args) -> None:
"""draws a line using any 2 args
Args:
slope (float): slope of the line
yInt (float): y-intercept of the line
p1 (Point): any point on the line
p2 (Point): any other point on the line
"""
if len(args) < 2:
raise Exception("Must have 2 references for a line in 2d space")
for key,value in args.items():
'%s = %s' % (key,value)
print(p2)
if __name__ == '__main__':
p1 = Point(1,1)
p2 = Point(2,2)
line1 = Line(p1=p1,p2=p2)
turtle.exitonclick()