mpotore.py

Created by schraf

Created on March 10, 2022

1.02 KB


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()

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.