Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_pseudo_maze.py
- import math
- import time
- from Tkinter import *
- import random
- root = Tk()
- width,height=680,680
- root.geometry("%dx%d+-10+0"%(width,height))
- canvas = Canvas(root,width=width, height=height, background="grey" )
- canvas.grid()
- running = True
- # size of square, in pixels
- square = 20
- above = {}
- lean = [0.1,0.9]
- def drawScreen():
- canvas.delete('all')
- # Python version of 10 PRINT happens here
- for y in range(0, height, square):
- for x in range(0, width, square):
- fwd = random.choice(lean) > 0.5
- try:
- yy = y-square
- m = above[x-square,yy]+above[x,yy]+above[x-square,y]
- if m in ('bff'):
- fwd = 1
- elif m in ('fbb'):
- fwd = 0
- except:
- 0
- if fwd:
- # /
- canvas.create_line((x, y), (x + square, y + square))
- above[x,y] = 'f'
- else:
- # \
- canvas.create_line((x, y + square), (x + square, y))
- above[x,y] = 'b'
- t = time.time()+5
- while t > time.time():
- canvas.update()
- while running:
- drawScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement