Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from random import *
- master = Tk()
- ch = 900
- cw = 900
- w = Canvas(master,
- width = cw,
- height = ch)
- w.pack()
- n = 10
- m = 10
- wV = [[True]*(m+1) for i in range (n)]
- wH = [[True]*(m) for i in range (n+1)]
- vis = [[False]*(m) for i in range (n)]
- p_x = []
- p_y = []
- n_vis = 0
- x = 0
- y = 0
- L = 0
- U = 1
- R = 2
- D = 3
- while n_vis!= (n*m):
- print(x, y)
- vis[x][y] = True
- p_x.append(x)
- p_y.append(y)
- if(not n_vis):
- n_vis += 1
- dirct = [L, U, R, D]
- if (x == 0) or vis[x-1][y]:
- dirct.remove(L)
- if (y == 0) or vis[x][y-1]:
- dirct.remove(U)
- if (x == (n-1)) or vis[x+1][y]:
- dirct.remove(R)
- if (y == (m-1)) or vis[x][y+1]:
- dirct.remove(D)
- if (len(dirct) < 1):
- p_x.pop()
- x = p_x.pop()
- p_y.pop()
- y = p_y.pop()
- else:
- d = dirct[randint(0, len(dirct)-1)]
- if d == L:
- wV[x][y] = False
- x-=1
- elif d == R:
- wV[x+1][y] = False
- x+=1
- elif d == U:
- wH[x][y] = False
- y-=1
- else:
- wH[x][y+1] = False
- y+=1
- n_vis+=1
- for i in range (n):
- for j in range (m+1):
- if wV[i][j]:
- x = cw/n*i
- y1 = ch/m*j
- y2 = ch/m*(j+1)
- w.create_line(x, y1, x, y2)
- for i in range (n+1):
- for j in range (m):
- if wH[i][j]:
- x1 = cw/n*i
- x2 = cw/n*(i+1)
- y = ch/m*j
- w.create_line(x1, y, x2, y)
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement