from math import ceil from kandinsky import fill_rect,draw_string from random import randint from time import sleep COUL = [(100,190,120),(255,235,130),(250,140,115),(250,105,107)] def affiche(l,c,t): m = max(l) for i in range(c): for j in range(c): x, y = 100 + 5 * j, 30 + 5 * i fill_rect(x, y, 5, 5, COUL[int(3 * l[c * i + j] / m)]) draw_string(str(min(l)) + "-" + str(m) + " ",155,190) draw_string(str(t) + " ",45,100) def mpotore(): aleaMax = randint(1,50) c = 20 l1 = [randint(0,aleaMax) for _ in range(c * c)] t = -1 while True: if t >= 0: l1 = list(l2) l2 = [0 for _ in range(c * c)] t += 1 for i in range(c): for j in range(1, c+1): d = ceil(l1[(c - 1 + c * i + j) % (c * c)] / 2) h = ceil(l1[c * i + (j + c - 2) % c] / 2) l2[c * i + j - 1] += d + h affiche(l2,c,t) sleep(.1) if t > 500 or max(l2) == min(l2): break mpotore()