w = 100 h = 100 from random import*;from kandinsky import*;c=range;d=[0]*(h*w);e=1 for x in c(h): for y in c(w): d[x+y*h]=randint(0,1) def q(): global e for f in c(h): for g in c(w): i=f+g*h;j=((d[(f-1)%h+((g-1)%w)*h]&e)>>(e-1))+((d[f+((g-1)%w)*h]&e)>>(e-1))+((d[(f+1)%h+((g-1)%w)*h]&e)>>(e-1))+((d[(f-1)%h+(g%w)*h]&e)>>(e-1))+((d[(f+1)%h+(g%w)*h]&e)>>(e-1))+((d[(f-1)%h+((g+1)%w)*h]&e)>>(e-1))+((d[f%h+((g+1)%w)*h]&e)>>(e-1))+((d[(f+1)%h+((g+1)%w)*h]&e)>>(e-1));k=d[i]&e;d[i]&=e|4;d[i]|=(j==3 or(k and j==2))<<(2-e) e = 3-e def p(): for l in c(h): for m in c(w): n=l+m*h;o=(1-((d[n]&e)>>(e-1)))*255 if d[n]&4!=d[n]&e:set_pixel(l,m,(o,o,o)) d[n]=(d[n]&3)|((d[n]&e)<<(3-e)) p() while True:q();p()