set display mode 1024,768,32
sync on
color backdrop 0
make object cube 1,1
hide object 1
 
 
centreradius=50
mazeradius=230
corridorwidth=30
x=mazeradius+5
y=mazeradius+5
 
ink rgb(200,200,255),0
 
start:
create bitmap 1,mazeradius*2+10,mazeradius*2+10
lock pixels
for r=centreradius to mazeradius step corridorwidth
  `corridor side walls
  ang1=rnd(360)
  ang2=ang1+350
  for n=ang1 to ang2
    line x+r*sin(n),y+r*cos(n),x+r*sin(n+1),y+r*cos(n+1)
  next n
  `corridor end walls
  if r<mazeradius
    ang3=ang1+rnd(350)
    line x+(r+1)*sin(ang3),y+(r+1)*cos(ang3),x+(r+corridorwidth)*sin(ang3),y+(r+corridorwidth)*cos(ang3)
  endif
  if r<mazeradius
    `sub-corridor side walls
    ang4=ang3+rnd(30)
    ang5=ang4+rnd(50)+100
    for n=ang4 to ang5
      line x+(r+corridorwidth/2)*sin(n),y+(r+corridorwidth/2)*cos(n),x+(r+corridorwidth/2)*sin(n+1),y+(r+corridorwidth/2)*cos(n+1)
    next n
    `sub-corridor end walls
    ang6=ang4+rnd(ang5-ang4)
    line x+(r+corridorwidth/2)*sin(ang6),y+(r+corridorwidth/2)*cos(ang6),x+(r+corridorwidth)*sin(ang6),y+(r+corridorwidth)*cos(ang6)
    `secondary sub-corridor side walls
    ang7=ang5+rnd(30)+10
    ang8=ang7+rnd(50)+80
    for n=ang7 to ang8
      line x+(r+corridorwidth/2)*sin(n),y+(r+corridorwidth/2)*cos(n),x+(r+corridorwidth/2)*sin(n+1),y+(r+corridorwidth/2)*cos(n+1)
    next n
    `secondary sub-corridor end walls
    ang9=ang7+rnd(ang8-ang7)
    if rnd(1)=0
      `make some go out to next wall
      line x+(r+corridorwidth/2)*sin(ang9),y+(r+corridorwidth/2)*cos(ang9),x+(r+corridorwidth)*sin(ang9),y+(r+corridorwidth)*cos(ang9)
    else
      `and some in to previous wall
      line x+(r+corridorwidth/2)*sin(ang9),y+(r+corridorwidth/2)*cos(ang9),x+(r)*sin(ang9),y+(r)*cos(ang9)
    endif
 
  endif
next r
 
unlock pixels
blur bitmap 1,2
 
get image 1,0,0,mazeradius*2+10,mazeradius*2+10,1
 
delete bitmap 1
 
sprite 1,screen width()/2-mazeradius,screen height()/2-mazeradius,1
 
do
text 0,0,"Press space to regenerate"
if spacekey()=1 then goto start
sync
loop