fromkandinskyimport*fromionimport*fromrandomimport*fromtimeimport*defmenu():globalmode,taillefill_rect(0,0,400,400,"black")draw_string("CHOIX DU MODE:",95,20,"orange","black")draw_string(" Aleatoire Manuel Predefini ",-10,70,"green","black")draw_string("[",-2,70,"white","black")draw_string("]",102,70,"white","black")mode=1whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT):ifkeydown(KEY_LEFT):ifmode<2:mode=3else:mode-=1elifkeydown(KEY_RIGHT):ifmode>2:mode=1else:mode+=1ifmode==1:# Aleatoire
draw_string(" Aleatoire Manuel Predefini ",-10,70,"green","black")draw_string("[",-2,70,"white","black")draw_string("]",102,70,"white","black")sleep(0.1)elifmode==2:# A choisir
draw_string(" Aleatoire Manuel Predefini ",-10,70,"green","black")draw_string("[",115,70,"white","black")draw_string("]",192,70,"white","black")sleep(0.1)elifmode==3:#Predefini
draw_string(" Aleatoire Manuel Predefini ",-10,70,"green","black")draw_string("[",207,70,"white","black")draw_string("]",313,70,"white","black")sleep(0.1)whilekeydown(KEY_EXE)orkeydown(KEY_OK):Truedraw_string("TAILLE DES CELLULES:",65,130,"orange","black")taille=6draw_string(" 1 2 3 4 5 6 7 8 9 ",17,170,"green","black")draw_string("[",21+30*(taille-1),170,"white","black")draw_string("]",21+30*(taille-1)+31,170,"white","black")whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT):ifkeydown(KEY_LEFT):taille-=1sleep(0.1)iftaille<1:taille=9elifkeydown(KEY_RIGHT):taille+=1sleep(0.1)iftaille>9:taille=1draw_string(" 1 2 3 4 5 6 7 8 9 ",17,170,"green","black")draw_string("[",21+30*(taille-1),170,"white","black")draw_string("]",21+30*(taille-1)+31,170,"white","black")ifkeydown(KEY_ZERO):taille=30defgeneration():fill_rect(0,0,400,400,"black")draw_string("GENERATION",108,90,"blue","black")sleep(0.5)fill_rect(320//2-16,115,3,3,"blue")sleep(0.5)fill_rect(320//2-3,115,3,3,"blue")sleep(0.5)fill_rect(320//2+10,115,3,3,"blue")sleep(0.5)deftrace_aleatoire():chiant=0.01x=0y=0fill_rect(0,0,400,400,"black")forcolonnesinrange(320//taille):forlignesinrange(222//taille):ifrandint(0,1)==0:fill_rect(x,y,taille,taille,"black")else:fill_rect(x,y,taille,taille,"white")y+=tailleifkeydown(KEY_EXE)orkeydown(KEY_OK):chiant=-1sleep(chiant)x+=tailley=0defchoisir_info():fill_rect(0,0,400,400,"black")draw_string("UTILISEZ LES FLECHES POUR",32,20,"white","black")draw_string("VOUS DEPLACER",95,40,"white","black")draw_string("APPUYEZ SUR OK POUR POSER UN",20,80,"white","black")draw_string("UN CARRE",120,100,"white","black")draw_string("UTILISEZ EXE POUR VALIDER",35,140,"white","black")whilekeydown(KEY_EXE)orkeydown(KEY_OK):Truewhilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):Truefill_rect(0,0,400,400,"black")defchargement():fill_rect(0,0,400,400,"black")draw_string("CHARGEMENT",108,90,"blue","black")foruinrange(270):fill_rect(25,180,u,15,"green")sleep(0.003)sleep(0.3)defchoisir():fill_rect(0,0,400,400,"black")x=155y=106whilenotx%taille==0:x+=1whilenoty%taille==0:y+=1while1:curseur(x,y)ifkeydown(KEY_UP):fill_rect(x,y,taille,taille,couleur_xy)y-=tailleify<1:y=222//taille*taille-taillewhilekeydown(KEY_UP):Trueelifkeydown(KEY_DOWN):fill_rect(x,y,taille,taille,couleur_xy)y+=tailleify>222//taille*taille:y=0whilekeydown(KEY_DOWN):Trueelifkeydown(KEY_LEFT):fill_rect(x,y,taille,taille,couleur_xy)x-=tailleifx<0:x=320//taille*taille-taillewhilekeydown(KEY_LEFT):Trueelifkeydown(KEY_RIGHT):fill_rect(x,y,taille,taille,couleur_xy)x+=tailleifx>320//taille*taille:x=0whilekeydown(KEY_RIGHT):Trueelifkeydown(KEY_OK):ifget_pixel(x,y)==(0,0,0):fill_rect(x,y,taille,taille,"white")else:fill_rect(x,y,taille,taille,"black")whilekeydown(KEY_OK):Trueelifkeydown(KEY_EXE):fill_rect(x,y,taille,taille,couleur_xy)whilekeydown(KEY_EXE):Truebreakdefcurseur(x,y):globalcouleur_xycouleur_xy=get_pixel(x,y)iftaille-2<0:d=0e=0else:d=taille-2e=taille-2fill_rect(x+1,y+1,d,e,"blue")defpredefini():globalshemawhilekeydown(KEY_EXE)orkeydown(KEY_OK):Truefill_rect(0,0,400,400,"black")draw_string("CHOIX DE LA FIGURE:",70,40,"orange","black")draw_string(" < Remplissage > ",53,110,"green","black")shema=1whilenot(keydown(KEY_EXE)orkeydown(KEY_OK)):ifkeydown(KEY_LEFT)orkeydown(KEY_RIGHT):ifkeydown(KEY_LEFT):whilekeydown(KEY_LEFT):Trueshema-=1ifshema<1:shema=3elifkeydown(KEY_RIGHT):whilekeydown(KEY_RIGHT):Trueshema+=1ifshema>3:shema=1ifshema==1:draw_string(" < Remplissage > ",53,110,"green","black")elifshema==2:draw_string(" < Canon > ",53,110,"green","black")elifshema==3:draw_string(" < Symetrie > ",53,110,"green","black")defremplissage():fill_rect(0,0,320//taille*taille,222//taille*taille,"white")defcannon():fill_rect(0,0,400,400,"black")x=155y=106whilenotx%taille==0:x+=1whilenoty%taille==0:y+=1fill_rect(x,y,taille,3*taille,"white")fill_rect(x-taille,y,taille,taille,"white")fill_rect(x-taille*2,y+taille,taille,taille,"white")defsymetrie():fill_rect(0,0,400,400,"black")x=115y=71whilenotx%taille==0:x+=1whilenoty%taille==0:y+=1fill_rect(x,y,3*taille,3*taille,"white")fill_rect(x+6*taille,y,3*taille,3*taille,"white")fill_rect(x,y+6*taille,3*taille,3*taille,"white")fill_rect(x+6*taille,y+6*taille,3*taille,3*taille,"white")fill_rect(x+taille,y+taille,taille,taille,"black")fill_rect(x+7*taille,y+taille,taille,taille,"black")fill_rect(x+taille,y+7*taille,taille,taille,"black")fill_rect(x+7*taille,y+7*taille,taille,taille,"black")defcouleur(x,y):globalBlanc,NoirBlanc=0Noir=0Col_Carre=get_pixel(x,y)ajout(x-1,y-1)# 1
ajout(x,y-1)# 2
ajout(x+taille+1,y-1)# 3
ajout(x-1,y)# 4
ajout(x+taille+1,y)# 5
ajout(x-1,y+taille+1)#6
ajout(x,y+taille+1)#7
ajout(x+taille+1,y+taille+1)#8
ifBlanc==3:return"white"elifBlanc==2andCol_Carre==(248,252,248):return"white"else:return"black"defajout(x,y):globalNoir,Blancifget_pixel(x,y)==(0,0,0):Noir+=1else:Blanc+=1liste_precedente=[""]liste=[]defecrire():globalliste,liste_precedenteliste_precedente=listeliste=[]x=0fortinrange(2):a=0b=0forcolonnesinrange(320//taille):forlignesinrange(222//taille):ift==0:liste.append(couleur(a,b))else:fill_rect(a,b,taille,taille,liste[x])x+=1b+=taillea+=tailleb=0deftest_fin_mort():if1==2:# if "white" not in liste:
fill_rect(0,0,400,400,"black")draw_string("TOUTES LES CELLULES SONT MORTES",4,90,"orange","black")draw_string("FIN DE LA SIMULATION",55,120,"orange","black")returnTruedeftest_fin_fige():ifliste_precedente==liste:fill_rect(0,0,400,400,"black")draw_string("TOUTES LES CELLULES SONT FIGEES",4,90,"orange","black")draw_string("FIN DE LA SIMULATION",55,120,"orange","black")returnTruemenu()ifmode==1:generation()trace_aleatoire()elifmode==2:choisir_info()chargement()choisir()elifmode==3:predefini()ifshema==1:remplissage()elifshema==2:cannon()elifshema==3:symetrie()whilekeydown(KEY_EXE)orkeydown(KEY_OK):Truewhilenot(keydown(KEY_EXE)orkeydown(KEY_OK)ortest_fin_fige()ortest_fin_mort()):ecrire()
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.