# 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)
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))```