fromkandinskyimportdraw_string,set_pixel,fill_rectfromrandomimportrandintfromionimport*defmenu(chaine,var,dec,mode,choix1,choix2):draw_string(chaine,10,v,'orange')draw_string("<"+""*(5+dec)+">",10+len(chaine)*10,v,'blue')whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):# if keydown(KEY_LEFT) or keydown(KEY_RIGHT):
ifmode=="nombre":var=(var-mini+keydown(KEY_RIGHT)-keydown(KEY_LEFT))%(maxi-mini+1)+minidraw_string(""+str(var)+" px ",10+(len(chaine)+1)*10+5*dec-5*len(str(var)),v,'purple')else:#mode booléen
draw_string(choix1*var+choix2*(1-var),10+(len(chaine)+2)*10,v,'purple')ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT):var=notvarwhilekeydown(KEY_LEFT)orkeydown(KEY_RIGHT):Truewhilekeydown(KEY_EXE)orkeydown(KEY_OK):Truereturnvardefcurseur(couleur):forposin[0,1]:fill_rect(dg+d*col+pos*(c+(s==3))+(s==1)+(s==2)-(s==3),dh+d*lig-2*(s==0)+5*(s==1)+(s==2)-(s==3),1,c+(s==3),couleur)fill_rect(dg+d*col+(s==1)+(s==2)-(s==3),dh+d*lig+pos*(c-(s==1)+(s==3))-2*(s==0)+5*(s==1)+(s==2)-(s==3),1+c+(s==3),1,couleur)returnNonedefcarre(i,j,couleur):ifrapide:foruinD:forvinD:set_pixel(dg+d*j+u,dh+d*i+v,couleur)else:fill_rect(dg+d*j,dh+d*i,c,c,couleur)v=20S=['o',chr(215),chr(176),'']s=0draw_string("Choix du symbole : ",10,v,'orange')draw_string("< >",10+19*10,v,'blue')draw_string(S[s],10+21*10,v,'purple')whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT):s=(s+keydown(KEY_RIGHT)-keydown(KEY_LEFT))%len(S)draw_string(S[s],10+21*10,v+4*(s==2),'purple')ifs==3:fill_rect(10+21*10+3,v+7,4,4,'purple')whilekeydown(KEY_LEFT)orkeydown(KEY_RIGHT):Truewhilekeydown(KEY_EXE)orkeydown(KEY_OK):Truec=9-2*smini=(s+2)%4+1ifs==3:v+=20rapide=True#ajouter menu de choix de vitesse
rapide=menu("Execution : ",rapide,3,"booleen","rapide","fluide")v+=20c=3mini=1maxi=15c=menu("Taille des cellules : ",c,2,"nombre","","")mini=max(0,5-c)#espacement mini
maxi=9v+=20e=5e=menu("Espacement : ",e,1,"nombre","","")v+=20alea=Truealea=menu("Initialisation : ",alea,6,"booleen","aléatoire","à choisir")v+=20clr=Trueclr=menu("Vieillissement : ",clr,7,"booleen","en couleur","monochrome")Naissance=[3]Survie=[2,3]foretapein[Naissance,Survie]:v+=20draw_string("Voisins pour "+"une naissance : "*(etape==Naissance)+"la survie : "*(etape==Survie),10,v,'orange')forninrange(9):draw_string(str(n),30+30*n,v+15,'purple'*(ninetape)+'grey'*(nnotinetape))pos=3whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT):forkin[-1,1]:draw_string("",30+30*pos+10*k,v+15)pos=(pos+(keydown(KEY_RIGHT)-keydown(KEY_LEFT)))%9draw_string("[",30+30*pos-10,v+15,'blue')draw_string("]",30+30*pos+10,v+15,'blue')#while keydown(KEY_LEFT) or keydown(KEY_RIGHT):True
ifkeydown(KEY_UP)orkeydown(KEY_DOWN):ifposinetape:etape.remove(pos)else:etape.append(pos)draw_string(str(pos),30+30*pos,v+15,'purple'*(posinetape)+'grey'*(posnotinetape))whilekeydown(KEY_UP)orkeydown(KEY_DOWN):Truewhilekeydown(KEY_EXE)orkeydown(KEY_OK):Trueetape.sort()etape.reverse()v+=20v+=20N=10draw_string("Nombre de cycles : ",10,v,'orange')draw_string("<"+5*""+">",10+19*10,v,'blue')draw_string(str(N),10+21*10,v,'purple')whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT)orkeydown(KEY_UP)orkeydown(KEY_DOWN):N=(N-1+(10*keydown(KEY_RIGHT)-10*keydown(KEY_LEFT)+keydown(KEY_UP)-keydown(KEY_DOWN)))%999+1draw_string(""+str(N)+"",10+20*10+5*(3-len(str(N))),v,'purple')whilekeydown(KEY_EXE)orkeydown(KEY_OK):Trued=c+eD=range(d-e)a=222//d#222//6=36
b=320//d#320//6=53
A=range(a)B=range(b)dg=(320-b*d+e)//2-2*(s==1)-(s==2)dh=(222-a*d+e)//2-5*(s==1)-(s==2)+(s==0)Liste=[[0forcolinB]forliginA]fill_rect(1,1,320,222,'white')ifalea:forliginA:forcolinB:Liste[lig][col]=2*randint(0,1)ifListe[lig][col]==2:ifs<3:draw_string(S[s],dg+d*col,(dh+d*lig)*(1-2*(s==0))+207*(s==0),'blue')else:carre(lig,col,'blue')else:col=b//2lig=a//2whilenotkeydown(KEY_SHIFT):curseur('orange')ifkeydown(KEY_RIGHT)orkeydown(KEY_LEFT)orkeydown(KEY_UP)orkeydown(KEY_DOWN):curseur('white')lig=(lig+keydown(KEY_DOWN)-keydown(KEY_UP))%acol=(col+keydown(KEY_RIGHT)-keydown(KEY_LEFT))%bifs==3ande==0:forranglin[-2,-1,0,1,2]:forrangcin[-2,-1,0,1,2]:ifListe[(lig+rangl)%a][(col+rangc)%b]>0:carre(lig+rangl,col+rangc,'blue')ifkeydown(KEY_EXE):ifs==0:Liste[a-1-lig][col]=2-Liste[a-1-lig][col]couleur='white'*(Liste[a-1-lig][col]==0)+'blue'*(Liste[a-1-lig][col]>0)else:Liste[lig][col]=2-Liste[lig][col]couleur='white'*(Liste[lig][col]==0)+'blue'*(Liste[lig][col]>0)ifs<3:draw_string(S[s],dg+d*col,dh+d*lig-7*(s==0),couleur)ifs==0ande<5andlig>0:forranginrange(a-lig,a):ifListe[rang][col]==0:breakdraw_string(S[s],dg+d*col,dh+d*(a-rang-1)-7*(s==0),'blue')ifs==1ande<5:forranginrange(lig+1,a):ifListe[rang][col]==0:breakdraw_string(S[s],dg+d*col,dh+d*rang,'blue')ifs==2:ife<3:forrangcinrange(col,a):forranglinrange(lig,a):ifListe[rangl][rangc]>0:draw_string(S[s],dg+d*rangc,dh+d*rangl,'blue')else:forranginrange(lig+1,a):ifListe[rang][col]>0:draw_string(S[s],dg+d*col,dh+d*rang,'blue')else:carre(lig,col,couleur)whilekeydown(KEY_EXE):Truecurseur('white')forgeninrange(N):foriinA:forjinB:Voisins=0forkin[-1,0,1]:forlin[-1,0,1]:if[k,l]!=[0,0]andListe[(i+k)%a][(j+l)%b]**2>3:Voisins+=1if (Liste[i][j]==0andVoisinsinNaissance)or(Liste[i][j]>0andVoisinsinSurvie):Liste[i][j]+=1couleur=(clr*min(25*Liste[i][j]-25,255),0,max(0,255+clr*(25-25*Liste[i][j])))else:Liste[i][j]*=-1couleur='white'ifListe[i][j]!=0:ifs<3:draw_string(S[s],dg+d*j,(dh+d*i)*(1-2*(s==0))+207*(s==0),couleur)else:carre(i,j,couleur)foriinA:forjinB:Liste[i][j]=2*((max(0,Liste[i][j])+1)//2)
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.