nsi_e22.py

Created by thomas-s

Created on October 06, 2023

1.81 KB

5 fractales faites par mes soins. Il faut lancer renduX() avec X un chiffre entre 1 et 5 inclu.


from kandinsky import *
from turtle import *

hideturtle()
speed(0)

#frac = 1 - Cellule 
#frac = 2 - Guirlande
def f(l,n,frac=2):
    if n == 0:
        forward(l)
    else:
        if frac == 1:
            forward(l)
        right(n*45)
        left(10*n)
        f(l*2/3,n-1,frac)
        f(l*2/3,n-1,frac)
        f(l*2/3,n-1,frac)
        if frac == 2:
            f(l*2/3,n-1,frac)

def background():
    for y in range(111):
        for x in range(320):
            set_pixel(x,y,(0,)*3)
    for y in range(21):
        for x in range(320):
            set_pixel(x,111+y,(round((255*y)/20),)*3)

def object(type_frac,l,n,x,y,orientation,size,c):
    penup()
    goto(x,y)
    setheading(orientation)
    pensize(size)
    colormode(255)
    color(c)
    pendown()
    f(l,n,type_frac)
    pensize(1)
    color((0,)*3)

def rendu1():
    background()
    object(2,30,5,-150,90,95,1,(255,255,255))
    object(2,30,5,20,90,95,1,(255,255,255))
    object(2,30,5,-10,-120,-95,1,(0,0,0))
    object(2,30,5,160,-120,-95,1,(0,0,0))

def rendu2():
    col = ((255,223,92),(255,233,52))
    object(1,16,5,-10,80,-26,2,col[0])
    object(1,16,5,5,-80,154,2,col[0])
    object(2,40,5,-150,-90,185,3,col[1])
    object(2,40,5,150,90,5,3,col[1])

def rendu3():
    fill_rect(0,0,320,222,(50,0,0))
    object(2,30,5,-150,90,95,2,(0,255,255))
    object(2,30,5,20,90,95,2,(0,255,255))
    object(2,30,5,-10,-120,-95,2,(0,255,255))
    object(2,30,5,160,-120,-95,2,(0,255,255))

def rendu4():
    object(2,40,5,-20,90,5,3,(255,233,52))
    object(2,40,5,20,-90,185,3,(255,233,52))

def rendu5():
    fill_rect(0,0,320,222,(0,)*3)
    object(1,40,5,40,-30,0,3,(255,233,52))
    object(1,13,5,120,90,42,2,(255,233,52))
    object(1,21,5,-30,65,25,2,(255,233,52))
    object(1,25,5,-120,-60,666,2,(255,233,52))
    object(1,18,5,-145,23,83,2,(255,233,52))

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.