Just started to write a maze script. There’s not much yet but it should run and produce a simple maze on the x y plane. To adjust the size, modify the cols and rows variables.
#!BPY
import copy,math
from Blender import BGL,Draw,Image,Material,Mesh,Redraw,Scene,Window
from random import randint,random,shuffle
def make_maze_mesh():
pi2=math.pi*2
#random()*pi2
editmode=Window.EditMode()
if editmode:Window.EditMode(0)
Window.WaitCursor(1)
d=0.1 # distance
rows,cols=36,48 ######## ADJUST rows & cols TO CHANGE THE SIZE
hcols=math.floor(cols/2-1)
vs=[]
for y in range(rows):
for x in range(cols):
vs.append([x*d,y*d,0])
es=[]
nodes=[[] for i in range(len(vs))]
mixnums=[i for i in range(len(vs))]
shuffle(mixnums)
tmp=cols*(rows-1)
tmp2=cols-1
for x in range(cols-1):
if x != hcols:
nodes[x].append(x+1)
nodes[x+1].append(x)
nodes[tmp+x].append(tmp+x+1)
nodes[tmp+x+1].append(tmp+x)
for y in range(rows-1):
nodes[y*cols].append((y+1)*cols)
nodes[(y+1)*cols].append(y*cols)
nodes[tmp2+y*cols].append(tmp2+(y+1)*cols)
nodes[tmp2+(y+1)*cols].append(tmp2+y*cols)
for i in mixnums:
n=i
if nodes[n]!=[]:continue
ri=randint(0,3)
while True:
if ri==0:nxt=n+cols
elif ri==1:nxt=n+1
elif ri==2:nxt=n-cols
else :nxt=n-1
nodes[n].append(nxt)
nodes[nxt].append(n)
if len(nodes[nxt])>1:break
n=nxt
for x in range(len(vs)):
for y in nodes[x]:
if x < y:
es.append([x,y])
me=Mesh.New('MazeMesh')
me.verts.extend(vs)
me.edges.extend(es)
scn=Scene.GetCurrent()
scn.objects.selected=[]
ob=scn.objects.new(me,'MazeMeshObj')
Window.WaitCursor(0)
if editmode:Window.EditMode(1)
if __name__=="__main__":
make_maze_mesh()