flocon2.py

Created by cent20

Created on April 08, 2022

1020 Bytes

Réalisé par un élève


# Auteur : Arnaud V.
# Réalisé par un de mes élèves de seconde 
# dans le cadre d'un DM "Les mathématiques sont belles", 2022, 3ème éd.
# https://twitter.com/nsi_xyz/status/1507684348820082690

# Flocon de koch https://fr.wikipedia.org/wiki/Flocon_de_Koch

from turtle import *
from kandinsky import *
from random import *
def fractal_side(length,sides):
  if sides==0:
    forward(length)
    return
  length/=3
  fractal_side(length,sides-1)
  left(60)
  fractal_side(length,sides-1)
  right(120)
  fractal_side(length,sides-1)
  left(60)
  fractal_side(length,sides-1)
  
def fractal_snowflake(sides, length):
  for i in range (sides):
    fractal_side(length,sides)
    right(360/sides)
    
    
def fractal(sides,length):
  for i in range (length):
    hideturtle()
    pencolor(i*6,i*6,i*6)
    fractal_snowflake(sides,length)
    forward(0.5)
    right(90)
    forward(0.625)
    left(90)
    length=length-1
    
penup()
backward(50)
left(90)
forward(70)
right(90)
pendown()
fractal(5,100)

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.