-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDFS.py
50 lines (37 loc) · 1.38 KB
/
DFS.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
from Graph import *
import time
import pygame,sys
import pygame.event as pe
import pygame.locals as pl
import Handle_Button
import Reset
# depth_first_search func for showing the depth first search
def depth_first_search(window, buttons ,colors , graph, nodes, edges):
graph.dfs(0)
while True:
window.fill(colors['paper'])
pygame.draw.line(window, colors['emerald'], (20, 70), (780, 70))
Handle_Button.draw_btns(buttons, colors['emerald'])
pos = pygame.mouse.get_pos()
for event in pe.get():
if event.type == pl.QUIT:
pygame.quit()
sys.exit()
if event.type == pl.KEYDOWN:
if event.key == pl.K_ESCAPE:
pygame.quit()
sys.exit()
if event.type == pl.MOUSEBUTTONDOWN:
if buttons[3].isOver(pos):
Reset.reset(window, buttons, colors, graph, nodes, edges)
if event.type == pl.MOUSEMOTION:
for button in buttons:
if button.isOver(pos):
button.color = colors['silver']
else:
button.color = colors['blacksteel']
graph.nodes = nodes
graph.edges = edges
# showing the depth first search
graph.dfs_show()
pygame.display.update()