z_episode4.py

Created by cent20

Created on April 12, 2023

1.22 KB

Joue avec ta #NumWorks : épisode 3

Dessine des rectangles avec une méthode carré.

Dans l’idée il faut produire l’image sans lire ni exploiter le code ci-dessous. https://twitter.com/nsi_xyz/status/1644425779030245377


# Joue avec ta NumWorks : episode 4
# https://twitter.com/nsi_xyz/status/

from kandinsky import fill_rect
from random import randint
from time import sleep


def quadrillage(xi, yi, xn, yn, larg, haut, e1, col):
    for x in range(xn):
        for y in range(yn):
            fill_rect(xi+x*(larg+e1), yi+y*(haut+e1), larg, haut, col)         


def quadrillage_aleat(n):
    for _ in range(n):
        fill_rect(0,0,320,222,(255,255,255))            # Effacer l'écran
        r, g, b = randint(0,255), randint(0,255), randint(0,255)  # Générer des couleurs aléatoires
        xi, yi = randint(0,10), randint(0,10)            # Position aléatoire de départ de la grille
        larg, haut = randint(10,42), randint(10,42)          # Taille d'un rectangle de base
        e1 = randint(2,max(2,(larg + haut)//4))            # Ecart entre les rectangles
        xn, yn = (320-xi+e1)//(larg+e1), (220-yi+e1)//(haut+e1)    # Nombre de rectangles pour ne pas dépasser
        """A noter : Les marges latérales n'ont pas été harmonisées"""        
        quadrillage(xi, yi, xn, yn, larg, haut, e1, (r,g,b))
        sleep(0.242)                         # Augmenter cette valeur en cas d'epilepsie


quadrillage_aleat(42)

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.