flocon.py

Created by christophe-prevot

Created on June 22, 2020

496 Bytes

Dessine un flocon de Koch avec le module Tortue. Fonction floconkoch : 2 paramètres : - le 1er (l) est la longueur de la branche initiale - le 2e (n) est le nombre de récurrences à effectuer


from turtle import *

def branche(l,n): ##l est la longueur de la branche initiale et n le nombre de recurrence##
    if (n==0):
        forward(l)
    else:
        branche(l/3,n-1)
        left(60)
        branche(l/3,n-1)
        right(120)
        branche(l/3,n-1)
        left(60)
        branche(l/3,n-1)

def floconkoch(l,n):
    reset()
    penup()
    goto(-150,50)
    pendown()
    speed(0)
    branche(l,n)
    right(120)
    branche(l,n)
    right(120)
    branche(l,n)

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.