# conway_couleur3.py

Created by florian-allard

Created on July 22, 2020

1.23 KB

```from kandinsky import fill_rect,draw_string,set_pixel
from random import randint
d = 5
D = range(1,d)
a = 222//d #222//6=36
b = 320//d #320//6=53
A = range(a)
B = range(b)
Liste = [[0 for col in B] for lig in A]
for lig in A:
for col in B:
Liste[lig][col] = 2*randint(0,1)
if Liste[lig][col] == 2:
#fill_rect(d*col,d*lig,d,d,'blue')
for u in D:
for v in D:
set_pixel(d*col+u,d*lig+v,'blue')#draw_string(chr(176),6*col,6*lig-1,'blue')

for gen in range(50):
for i in A:
for j in B:
Voisins = 0
for k in [-1,0,1]:
for l in [-1,0,1]:
if [k,l] != [0,0] and Liste[(i+k)%a][(j+l)%b]**2 > 3:
Voisins += 1
if Voisins == 3 or ( Liste[i][j] > 0 and Voisins == 2 ):
Liste[i][j] += 1 #Une cellule tout juste créée est à 1
couleur = (min(25*Liste[i][j]-25,255),0,max(0,255-25*Liste[i][j]+25))
else:
Liste[i][j] *= -1
couleur = 'white'
if Liste[i][j] != 0:
#draw_string(chr(176),6*j,6*i-1,couleur)
#fill_rect(d*j,d*i,d,d,couleur)
for u in D:
for v in D:
set_pixel(d*j+u,d*i+v,couleur)
for i in A:
for j in B:
Liste[i][j] = 2*((max(0,Liste[i][j])+1)//2)```