Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. from tkinter import *
  2. from random import *
  3.  
  4. master = Tk()
  5.  
  6. ch = 900
  7. cw = 900
  8. w = Canvas(master,
  9. width = cw,
  10. height = ch)
  11. w.pack()
  12.  
  13. n = 10
  14. m = 10
  15.  
  16. wV = [[True]*(m+1) for i in range (n)]
  17. wH = [[True]*(m) for i in range (n+1)]
  18. vis = [[False]*(m) for i in range (n)]
  19. p_x = []
  20. p_y = []
  21. n_vis = 0
  22.  
  23. x = 0
  24. y = 0
  25.  
  26. L = 0
  27. U = 1
  28. R = 2
  29. D = 3
  30.  
  31. while n_vis!= (n*m):
  32. print(x, y)
  33. vis[x][y] = True
  34.  
  35. p_x.append(x)
  36. p_y.append(y)
  37.  
  38. if(not n_vis):
  39. n_vis += 1
  40.  
  41. dirct = [L, U, R, D]
  42. if (x == 0) or vis[x-1][y]:
  43. dirct.remove(L)
  44. if (y == 0) or vis[x][y-1]:
  45. dirct.remove(U)
  46. if (x == (n-1)) or vis[x+1][y]:
  47. dirct.remove(R)
  48. if (y == (m-1)) or vis[x][y+1]:
  49. dirct.remove(D)
  50.  
  51.  
  52. if (len(dirct) < 1):
  53. p_x.pop()
  54. x = p_x.pop()
  55. p_y.pop()
  56. y = p_y.pop()
  57. else:
  58. d = dirct[randint(0, len(dirct)-1)]
  59.  
  60. if d == L:
  61. wV[x][y] = False
  62. x-=1
  63. elif d == R:
  64. wV[x+1][y] = False
  65. x+=1
  66. elif d == U:
  67. wH[x][y] = False
  68. y-=1
  69. else:
  70. wH[x][y+1] = False
  71. y+=1
  72. n_vis+=1
  73.  
  74. for i in range (n):
  75. for j in range (m+1):
  76. if wV[i][j]:
  77. x = cw/n*i
  78. y1 = ch/m*j
  79. y2 = ch/m*(j+1)
  80. w.create_line(x, y1, x, y2)
  81.  
  82. for i in range (n+1):
  83. for j in range (m):
  84. if wH[i][j]:
  85. x1 = cw/n*i
  86. x2 = cw/n*(i+1)
  87. y = ch/m*j
  88. w.create_line(x1, y, x2, y)
  89.  
  90. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement