nsi_e22.py

Created by r0baiyn

Created on October 03, 2023

1.14 KB

Un tapis de Siepinsky récursif. Utilisez fractale(42) pour le meilleur résultat ;)


from kandinsky import fill_rect as rect

bg = True
def fractale(n):
    global bg
    if bg:
        rect(0, 0, 320, 240, (148,113,222))
        bg = False
    if n == 0:
        bg = True
        return
    elif n == 1:
        rect(124, 75, 72, 72, (255,255,255))
    
    elif n == 2:
        longueur = 0
        largeur = 0
        for i in range(3):
            for y in range(5):
                rect(4 + longueur, 27 + largeur, 24, 24, (255,255,255))
                longueur = (y+1)%5 * 72
            largeur = (i+1)%3 * 72
            
    elif n == 3:
        longueur = 0
        largeur = 0
        for i in range(9):
            for y in range(15):
                rect(-12 + longueur, 11 + largeur, 8, 8, (255,255,255))
                longueur = (y+1)%15 * 24
            largeur = (i+1)%15 * 24
    
    elif n == 4:
        longueur = 0
        largeur = 0
        for i in range(27):
            for y in range(45):
                rect(-19 + round(longueur), 7 + round(largeur), 2, 2, (255,255,255))
                longueur = ((y+1)%45 * 8)+ 2
            largeur = ((i+1)%45 * 8)+ 1/5
    if n>5:
        n=5
    fractale(n-1)

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.