cadenas.py

Created by schraf

Created on August 25, 2021

790 Bytes


from kandinsky import draw_string, fill_rect
from random import choice, randint

RO, BL, NR, VE = (248,0,0), (40,160,216), (0,0,0), (0,255,0)
# etats des cases
data = [0 for i in range(512)]

# ecran noir
fill_rect(0,0,320,222,NR)
# nb de 8
t = 0

while True:
  # case qui va etre changee
  n = randint(0, 511)
  if data[n] != 8:
    # +1 ou -1 en restant entre 0 et 9
    v = max(0,min(data[n] + choice([-1,1]), 9))
    data[n] = v
    # nb de 8 deja sur l'ecran
    if v == 8: t +=1
    if t == 512: break
    # affichage avec couleur RO, BL ou VE si 8
    draw_string(str(v), 10 * (n % 32), -2 + 15 * (n // 32), choice([BL,RO]) if v != 8 else VE, NR)
# Ecran final avec inversion couleurs
for n in range(512):
  draw_string("8", 10 * (n % 32), -2 + 15 * (n // 32), NR, VE)

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.