-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdijkstrasVisualizer.py
More file actions
138 lines (76 loc) · 2.93 KB
/
dijkstrasVisualizer.py
File metadata and controls
138 lines (76 loc) · 2.93 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import tkinter as tk
import time
from Node import Node
from Dijkstras import dijkstrasRecursion, initializeDijkstras
grid = [ [None]*20 for _ in range(20) ]
root = tk.Tk()
global gameframe
gameframe = tk.Frame(root)
gameframe.pack()
#Make the start dijkstras button
startButton = tk.Label(gameframe,text='Start Dijkstras',bg= "grey")
startButton.grid(row=0, column=0, columnspan= 15)
startButton.bind('<Button-1>', lambda e:doDijkstras())
# Label(master, image = img1).grid(row = 0, column = 2,
# columnspan = 2, rowspan = 2, padx = 5, pady = 5)
for i,row in enumerate(grid):
for j,column in enumerate(row):
name = str(i)+str(j)
L = tk.Label(gameframe,text=' ',bg= "grey")
L.grid(row=i+1,column=j+1,padx='3',pady='3')
L.bind('<Button-1>',lambda e,i=i,j=j:on_click(i,j,e))
node = Node(i, j, L)
grid[i][j] = node
def on_click(row, col, event):
print(f"clicked: {row},{col}. prevNode = {grid[row][col].prevNode}, distance = {grid[row][col].distance}")
grid[row][col].widget['bg'] = 'red'
#Toggle the passability of the terrain
if grid[row][col].isPassable == True:
grid[row][col].isPassable = False
grid[row][col].widget['bg'] = 'black'
else:
grid[row][col].isPassable = True
grid[row][col].widget['bg'] = 'grey'
def doDijkstras():
startX = 5
startY = 5
finishX = 18
finishY = 18
initializeDijkstras(grid, startX, startY, finishX, finishY)
dijkstrasRecursion(grid, root)
root.mainloop()
# global gameframe
# gameframe = tk.Frame(root)
# gameframe.pack()
# #Make the start dijkstras button
# startButton = tk.Label(gameframe,text='Start Dijkstras',bg= "grey")
# startButton.grid(row=0, column=0)
# startButton.bind('<Button-1>', lambda e:doDijkstras())
# for i,row in enumerate(grid):
# for j,column in enumerate(row):
# name = str(i)+str(j)
# L = tk.Label(gameframe,text=' ',bg= "grey")
# L.grid(row=i+1,column=j+1,padx='3',pady='3')
# L.bind('<Button-1>',lambda e,i=i,j=j:on_click(i,j,e))
# node = Node(i, j, L)
# grid[i][j] = node
# def on_click(row, col, event):
# print(f"clicked: {row},{col}")
# grid[row][col].widget['bg'] = 'red'
# #Toggle the passability of the terrain
# if grid[row][col].isPassable == True:
# grid[row][col].isPassable = False
# grid[row][col].widget['bg'] = 'black'
# else:
# grid[row][col].isPassable = True
# grid[row][col].widget['bg'] = 'grey'
# def doDijkstras():
# initializeDijkstras(grid, 0, 0, 5, 5)
# print("Totally doing dijkstras rn")
# # Until we get to the final node, do this
# i = 0
# while i < 15:
# dijkstras(grid, gameframe)
# time.sleep(.5)
# i+=1
# root.mainloop()