from graphics import *
class Toothpick:
LENGTH = 63
def __init__(self,x1,y1,d):
self.x = x1
self.y = y1
self.direction = d
self.alreadyShown = False
def show(self,win):
if self.direction == "h":
p1 = Point(self.x-(Toothpick.LENGTH)//2,self.y)
p2 = Point(self.x+(Toothpick.LENGTH)//2,self.y)
line = Line(p1,p2)
line.draw(win)
else:
p1 = Point(self.x,self.y-(Toothpick.LENGTH)//2)
p2 = Point(self.x,self.y+(Toothpick.LENGTH)//2)
line = Line(p1,p2)
line.draw(win)
self.alreadyShown = True
from graphics import *
WIDTH = 600
HEIGHT = 600
def main():
win = GraphWin("Toothpick Pattern", 600, 600)
win.setBackground("white")
win.setCoords(-WIDTH/2,-HEIGHT/2,WIDTH/2,HEIGHT/2)
t1 = Toothpick(100,100,"h")
t2 = Toothpick(200,200,"v")
t3 = Toothpick(30,30,"h")
t1.show(win)
t2.show(win)
t3.show(win)
if t3.alreadyShown:
print("t3 already on canvas")
else:
t3.show(win)
win.getMouse()
win.close()
main()
t3 already on canvas