Draws a perfect maze, you can change size on the path, number of row & column and so on, by default the program retry if it hit a MemoryError error, cause for some reason sometime it eat all the RAM… The strange thing is that it works on my N100 with upsilon but not on the emulator
from kandinsky import draw_string as st, fill_rect as rt,set_pixel as px from random import random as ra,randint as ri,choice as ch from ion import keydown as k from time import sleep def rc(): return (ri(0,255),ri(0,255),ri(0,255)) def laby(X,Y,s,S,n): pos=[(0,0)] visted=[[0,]*n for i in range(n)] visted[0][0]=1 dirs=((-1,0),(1,0),(0,-1),(0,1)) # rt(X-S,Y-S,(s+S)*n+S,(s+S)*n+S,(255,)*3) # for i in range(n): # for j in range(n): # rt(X+i*(s+S),Y+j*(s+S),S,S,(255,0,0)) # I=0 while pos: allows=[] x,y=pos.pop() for i in dirs: if 0<=x+i[0]<n: if 0<=y+i[1]<n: if visted[x+i[0]][y+i[1]]==0: allows.append(i) if allows: d=ch(allows) n_x,n_y=x+d[0],y+d[1] pos.append((x,y)) pos.append((n_x,n_y)) visted[n_x][n_y]=1 # if d[0]: # w=S*d[0] # elif d[0]>0: # w=s # else:w=-s # if d[1]: # h=S*d[1] # elif d[1]>0: # h=s # else:h=-s w=s*d[0]if d[0]else 1 h=s*d[1]if d[1]else 1 _X=X+s*x _Y=Y+s*y # _X+=S*(n_x) # _Y+=S*(n_y) # print("n_x:",n_x,"n_y:",n_y,"→",_X,_Y,w,h) rt(_X,_Y,w,h,(255,)*3) # rt(_X,_Y,w,h,(255-10*I,0,0)) # rt(X+s*x-s//2,Y+s*y-s//2,w,h,(0,0,255)) # sleep(0.5) # I+=1 while 1: a=1 while a: try: rt(0,0,320,222,(0,0,0)) laby(0,0,5,5,50) a=0 except MemoryError:1 while not k(4)|k(52):1