conway_couleur.py

Created by florian-allard

Created on March 10, 2021

1006 Bytes

Suite à la mise à jour du simulateur en ligne, l’espace entre 2 colonnes doit être de 9 plutôt que 8, sinon une partie du symbole est effacée.


from kandinsky import draw_string
from random import randint
a = 23 #222//8=27
b = 35 #320//9=35
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] = randint(0,1)
    if Liste[lig][col] == 1:
      draw_string(chr(176),9*col,8*lig+2,'blue')
Nouv = [[0 for col in B] for lig in A]
Age = [[0 for col in B] for lig in A]

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]:
            Voisins += Liste[(i+k)%a][(j+l)%b]
      if Voisins == 3 or ( Liste[i][j] == 1 and Voisins == 2 ):
        Nouv[i][j] = 1
        Age[i][j] += Liste[i][j]
        couleur = (min(50*Age[i][j],255),0,max(0,255-50*Age[i][j]))
      else:
        Nouv[i][j] = 0
        Age[i][j] = 0
        couleur = 'white'
      if Liste[i][j]+Nouv[i][j] > 0:
        draw_string(chr(176),9*j,8*i+2,couleur)
  Liste = [[Nouv[m][n] for n in B] for m in A]

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.