""" The purpose of this module is to build the maze and pathway that the '.gif's' follow. """ from Tkinter import * import time class Maze(object): def __init__(self): #initial position of .gif self.xp = 100 self.yp = 600 def createWall((x0, y0), (x1, y1), colour = 'blue', width = 3): """ Create a wall from (x0, y0) to (x1, y1). """ canvasOne.create_line(x0, y0, x1, y1, width = width, fill = colour) outerWall = [(450, 640), (475, 640), (475, 640), (475, 690), (475, 690), (790, 690), (790, 690), (790, 530), (790, 530), (660, 530), (660, 530), (660, 360), (790, 360), (790, 10), (790, 10), (10, 10), (10, 10), (10, 360), (10, 360), (150, 360), (150, 360), (150, 530), (150, 530), (10, 530), (10, 530), (10, 690), (10, 690), (325, 690), (325, 690), (325, 640), (325, 640), (350, 640), (350, 630), (350, 630), (315, 630), (315, 680), (20, 680), (20, 680), (20, 560), (20, 540), (160, 540), (160, 540), (160, 350), (20, 350), (20, 350), (20, 20), (20, 20), (380, 20), (380, 20), (380, 130), (380, 130), (420, 130), (420, 130), (420, 20), (420, 20), (780, 20), (780, 350), (780, 350), (650, 350), (650, 350), (650, 540), (650, 540), (780, 540), (780, 540), (780, 680), (780, 680), (485, 680), (485, 630), (485, 630), (450, 630), (450, 630), (450, 640)] walls = [outerWall] for wall in walls: for i in range(len(wall)-1): createWall(outerWall[i], outerWall[i+1]) canvasOne.create_line(350, 630, 450, 630, width = 3, fill = 'gold', tag = 'gate') topLeftBox = [(130, 105), (130, 125), (130, 125), (250, 125), (250, 125), (250, 105), (130, 105), (250, 105)] secondTopLeftBox = [(160, 215), (160, 225), (160, 215), (230, 215), (230, 215), (230, 225), (160, 225), (230, 225)] topRightBox = [(545, 105), (545, 125), (545, 125), (665, 125), (665, 125), (665, 105), (545, 105), (665, 105)] secondTopRightBox = [(560, 215), (560, 225), (560, 215), (625, 215), (625, 215), (625, 225), (625, 225), (560, 225)] boxes = [topLeftBox, secondTopLeftBox, topRightBox, secondTopRightBox] for box in boxes: for i in range(len(box)-1): createWall(topLeftBox[i], topLeftBox[i+1]), createWall(secondTopLeftBox[i], secondTopLeftBox[i+1]), createWall(topRightBox[i], topRightBox[i+1]), createWall(secondTopRightBox[i], secondTopRightBox[i+1]) middleT = [(345, 240), (455, 240), (345, 240), (345, 240), (345, 250), (395, 250), (395, 250), (395, 335), (395, 335), (405, 335), (405, 335), (405, 250), (405, 250), (455, 250), (455, 250), (455, 240)] leftSidewaysT = [(275, 340), (275, 500), (275, 340), (285, 340), (285, 340), (285, 415), (285, 415), (345, 415), (345, 415), (345, 425), (285, 425), (345, 425), (285, 425), (285, 500), (275, 500), (285, 500)] rightSidewaysT = [(525, 340), (525, 500), (525, 340), (515, 340), (515, 340), (515, 415), (515, 415), (455, 415), (455, 415), (455, 425), (515, 425), (455, 425), (515, 425), (515, 500), (515, 500), (525, 500)] Ts = [middleT, leftSidewaysT, rightSidewaysT] for t in Ts: for i in range(len(t)-1): createWall(middleT[i], middleT[i+1]), createWall(leftSidewaysT[i], leftSidewaysT[i+1]), createWall(rightSidewaysT[i], rightSidewaysT[i+1]) #This is the paths through the maze #bottom left to middle x = 40 for i in range(9): x += 20 canvasOne.create_rectangle(x, 610, x+5, 615, fill = 'white') #left path built north to south y = 290 for i in range(15): y += 20 canvasOne.create_rectangle(220, y, 225, y+5, fill = 'white') #left path above left indent x = 60 for i in range(14): x +=20 canvasOne.create_rectangle(x, 290, x+5, 295, fill = 'white') #left path to top y = 315 for i in range(13): y -= 20 canvasOne.create_rectangle(60, y, 65, y-5, fill = 'white') #top, west to middle indent x = 60 for i in range(12): x += 20 canvasOne.create_rectangle(x, 50, x+5, 55, fill = 'white') #top indent to bottom of middle T y = 50 for i in range(11): y += 20 canvasOne.create_rectangle(300, y, 305, y+5, fill = 'white') #top west to east above middle T and below top indent x = 60 for i in range(33): x += 20 canvasOne.create_rectangle(x, 170, x+5, 175, fill = 'white') #top north to south, right ot top indent y = 30 for i in range(13): y += 20 canvasOne.create_rectangle(500, y, 505, y+5, fill = 'white') #top indent to east x = 500 for i in range(12): x += 20 canvasOne.create_rectangle(x, 50, x+5, 55, fill = 'white') #top right North to south y = 30 for i in range(13): y +=20 canvasOne.create_rectangle(740, y, 745, y+5, fill = 'white') #middle T towards right wall x = 440 for i in range(14): x += 20 canvasOne.create_rectangle(x, 290, x+5, 295, fill = 'white') #left of T North to South y = 290 for i in range(4): y +=20 canvasOne.create_rectangle(340, y, 345, y+5, fill = 'white') #right of T North to South y = 290 for i in range(4): y += 20 canvasOne.create_rectangle(460, y, 465, y+5, fill = 'white') #below T west to east x = 340 for i in range(5): x += 20 canvasOne.create_rectangle(x, 370, x+5, 375, fill = 'white') #below T to gate North to South y = 370 for i in range(10): y += 20 canvasOne.create_rectangle(400, y, 405, y+5, fill = 'white') #from West to East above gate x = 220 for i in range(18): x += 20 canvasOne.create_rectangle(x, 570, x+5, 575, fill = 'white') #right side north to south right T y = 290 for i in range(16): y += 20 canvasOne.create_rectangle(580, y, 585, y+5, fill = 'white') #right side gate to right wall x = 580 for i in range(8): x += 20 canvasOne.create_rectangle(x, 610, x+5, 615, fill = 'white') """ #process image for use image = "DustY1.gif" photo = PhotoImage(file=image) xp = 100 yp = 600 ph = canvasOne.create_image(xp,yp,image=photo) ph #direction will determine if the direction of the move is vertical or horizontal def direction(event): if event.x <= xp+10 and event.x >= xp-10: #tolerance for inaccurate click newY = event.y onClickVertical(newY, xp, yp) if event.y <= yp+10 and event.y >= yp-10: #tolerance for inaccurate click newX = event.x onClickHorizontal(newX, xp, yp) #onClick Vertical moves the .gif based on where the mouse is clicked #newY is new location for yp def onClickVertical(newY, xp, yp): print 'here' for i in range(newY): yp += .8 canvasOne.coords(ph, xp, yp) time.sleep(.001) canvasOne.update() return xp, yp #onClick Horizontal moves the .gif based on where the mouse is clicked #newX is new location for xp def onClickHorizontal(newX, xp, yp): for i in range(newX): xp += .8 canvasOne.coords(ph, xp, yp) time.sleep(.001) canvasOne.update() return xp, yp canvasOne.bind("", direction) """ root = Tk() root.title("Background") canvasOne = Canvas(width = 800, height = 700, bg = 'black') createWall(450, 640, 475, 640) canvasOne.pack() root.mainloop()