Automate cellulaire à une dimension: chaque ligne est déterminée à partir de celle directement en haut de celle ci. Essayez auto(0,1,1,0,0,0,1,0). Chaque pixel est alors déterminé à partir des trois en haut de lui, pouvant être, chacun, soit noir soit blanc. Ainsi, dans auto(a,b,c,d,e,f,g,h), les 8 arguments (mettre 0 si blanc/1 si noir pour chaque cas) traitent des possibilités (pour N noir et B blanc): a=BBB; b=BBN; c=BNB; d=BNN; e=NBB; f=NBN; g=NNB; h=NNN
from math import * import kandinsky #for this to be clear white=0 black=1 def blck(x,y,col): kandinsky.set_pixel(x,y,kandinsky.color(255-col*255,255-col*255,255-col*255)) def isblck(x,y): if kandinsky.get_pixel(x,y)==kandinsky.color(0,0,0): return 1 if kandinsky.get_pixel(x,y)!=kandinsky.color(0,0,0): return 0 def auto(a,b,c,d,e,f,g,h): cx=1 cy=1 #setup first points blck(160,0,1) #blck(200,0,1) #main loop for loop in range(222): #white=0 #blck=1 for loop in range(318): #t1=white if isblck(cx-1,cy-1)==0: #t2=white if isblck(cx,cy-1)==0: #t3=white000 if isblck(cx+1,cy-1)==0: blck(cx,cy,a) #t3=blck001 if isblck(cx+1,cy-1)==1: blck(cx,cy,b) #t2=blck if isblck(cx,cy-1)==1: #t3=white010 if isblck(cx+1,cy-1)==0: blck(cx,cy,c) #t3=blck011 if isblck(cx+1,cy-1)==1: blck(cx,cy,d) #t1=dark if isblck(cx-1,cy-1)==1: #t2=white if isblck(cx,cy-1)==0: #t3=white100 if isblck(cx+1,cy-1)==0: blck(cx,cy,e) #t3=blck101 if isblck(cx+1,cy-1)==1: blck(cx,cy,f) #t2=black if isblck(cx,cy-1)==1: #t3=white110 if isblck(cx+1,cy-1)==0: blck(cx,cy,g) #t3=blck111 if isblck(cx+1,cy-1)==1: blck(cx,cy,h) cx+=1 cx=1 cy+=1 #auto(0,1,0,1,1,0,0,1)