Advertisement
here2share

# Tk_pseudo_maze.py

Jun 20th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # Tk_pseudo_maze.py
  2.  
  3. import math
  4. import time
  5. from Tkinter import *
  6. import random
  7.  
  8. root = Tk()
  9. width,height=680,680
  10. root.geometry("%dx%d+-10+0"%(width,height))
  11. canvas = Canvas(root,width=width, height=height, background="grey" )
  12. canvas.grid()
  13.  
  14. running = True
  15.  
  16. # size of square, in pixels
  17. square = 20
  18. above = {}
  19. lean = [0.1,0.9]
  20. def drawScreen():
  21.     canvas.delete('all')
  22.     # Python version of 10 PRINT happens here
  23.     for y in range(0, height, square):
  24.         for x in range(0, width, square):
  25.             fwd = random.choice(lean) > 0.5
  26.             try:
  27.                 yy = y-square
  28.                 m = above[x-square,yy]+above[x,yy]+above[x-square,y]
  29.                 if m in ('bff'):
  30.                     fwd = 1
  31.                 elif m in ('fbb'):
  32.                     fwd = 0
  33.             except:
  34.                 0
  35.             if fwd:
  36.                 # /
  37.                 canvas.create_line((x, y), (x + square, y + square))
  38.                 above[x,y] = 'f'
  39.             else:
  40.                 # \
  41.                 canvas.create_line((x, y + square), (x + square, y))
  42.                 above[x,y] = 'b'
  43.     t = time.time()+5
  44.     while t > time.time():
  45.         canvas.update()
  46.  
  47. while running:
  48.     drawScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement