fractal_nsi.py

Created by remi-aerts04

Created on November 02, 2021

1.56 KB

Cree une spirale grâce à la courbe de Koch


from turtle import *
hideturtle()
def frac(longueur, n):#création de la forme/fractale : script original (https://my.numworks.com/python/cent20/flocon
    if n == 0:
        fd(longueur)
    else:
        frac(longueur / 3, n - 1)
        lt(108)
        frac(longueur / 3, n - 1)
        rt(72)
        frac(longueur / 3, n - 1)
        rt(72)
        frac(longueur / 3, n - 1)
        rt(72)
        frac(longueur / 3, n - 1)
        lt(108)
        frac(longueur / 3, n - 1)
        
def spirale_rouge(repetition, longueur, r, g , b, etape):#première spirale rouge->jaune en récursivité
    color(r, g, b)
    if repetition == 0 :
        frac(longueur, etape)
    else:
        frac(longueur, etape)
        rt(60)
        if g+200//repetition < 255 :
            g+=200//repetition
        spirale_rouge(repetition - 1, longueur + 80//repetition, r, g, b, etape)
        
def spirale_bleue(repetition, longueur, r, g , b, etape, compteur, angle):#deuxième spirale bleu->bleu clair en récursivité
    color(r, g, b)
    if repetition == 0 :
        frac(longueur, etape)
    else:
        frac(longueur, etape)
        rt(angle)
        if g+200//repetition < 255 :
            g+=200//repetition
        spirale_bleue(repetition - 1, longueur + 80//repetition, r, g, b, etape, compteur + 1, angle-0.1425*compteur)
        
pu();goto(0, 0);pd();speed(10)
spirale_rouge(10, 10, 250, 0, 0, 3)# couleur rouge + 10 éléments et longueur initiale 10
pu();goto(0, 0);pd();lt(25)
spirale_bleue(10, 8, 0, 0, 250, 3, 0, 55)# couleur bleue + 10 éléments et longueur initiale 8

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.