Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,67 @@
|
|||
"""
|
||||
we use the following conventions:
|
||||
directions 0: up, 1: left, 2: down: 3: right
|
||||
|
||||
pixel white: True, black: False
|
||||
|
||||
turn right: True, left: False
|
||||
"""
|
||||
|
||||
# number of iteration steps per frame
|
||||
# set this to 1 to see a slow animation of each
|
||||
# step or to 10 or 100 for a faster animation
|
||||
|
||||
STEP = 100
|
||||
count = 0
|
||||
|
||||
def setup():
|
||||
global x, y, direction
|
||||
|
||||
# 100x100 is large enough to show the
|
||||
# corridor after about 10000 cycles
|
||||
size(100, 100, P2D)
|
||||
|
||||
background(255)
|
||||
x = width / 2
|
||||
y = height / 2
|
||||
direction = 0
|
||||
|
||||
def draw():
|
||||
global count
|
||||
for i in range(STEP):
|
||||
count += 1
|
||||
pix = get(x, y) != -1 # white =-1
|
||||
setBool(x, y, pix)
|
||||
|
||||
turn(pix)
|
||||
move()
|
||||
|
||||
if (x < 0 or y < 0 or x >= width or y >= height):
|
||||
println("finished")
|
||||
noLoop()
|
||||
break
|
||||
|
||||
if count % 1000 == 0:
|
||||
println("iteration {}".format(count))
|
||||
|
||||
def move():
|
||||
global x, y
|
||||
if direction == 0:
|
||||
y -= 1
|
||||
elif direction == 1:
|
||||
x -= 1
|
||||
elif direction == 2:
|
||||
y += 1
|
||||
elif direction == 3:
|
||||
x += 1
|
||||
|
||||
def turn(rightleft):
|
||||
global direction
|
||||
direction += 1 if rightleft else -1
|
||||
if direction == -1:
|
||||
direction = 3
|
||||
if direction == 4:
|
||||
direction = 0
|
||||
|
||||
def setBool(x, y, white):
|
||||
set(x, y, -1 if white else 0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue