from kandinsky import fill_rect from time import monotonic, sleep from ion import keydown, KEY_OK TAILLE = 40 X0 = 100 Y0 = 30 fill_rect(0, 0, 320, 222, (0, 0, 0)) def affiche_chiffre(n, x=X0, y=Y0, taille=TAILLE, cases=4): for i in range(cases): bit = (int(n) >> i) & 1 couleur = (250,120,140) if bit else (170,170,180) ypos = y + (3 - i) * (taille + 2) fill_rect(x, ypos, taille, taille, couleur) start_time = monotonic() last_update = start_time running = True while True: if monotonic() - last_update > 0.1 and running: last_update = monotonic() elapsed = last_update - start_time minutes = elapsed // 60 tens_of_minutes = int(minutes // 10) units_of_minutes = int(minutes % 10) seconds = int(elapsed % 60) tens_of_seconds = seconds // 10 units_of_seconds = seconds % 10 tenths = int(10 * (elapsed % 1)) affiche_chiffre(tens_of_minutes, x=50, cases=2) affiche_chiffre(units_of_minutes, x=52 + TAILLE) affiche_chiffre(tens_of_seconds, x=58 + 2*TAILLE, cases=3) affiche_chiffre(units_of_seconds, x=60 + 3*TAILLE) affiche_chiffre(tenths, x=66 + 4*TAILLE) if keydown(KEY_OK): running = not running sleep(0.3)