Exercices sur les fractales

Exercices sur les fractales#

!pip install ipycanvas
from ipycanvas import Canvas
c = Canvas(width=200,height=200,sync_image_data=True)
def segment(x1,y1,x2,y2):
   c.stroke_line(x1,200-y1,x2,200-y2)
segment(0,0,100,0)
segment(0,0,0,100)
def fractale(x,y,l,etape):
    if etape == 0:
        segment(x,y,x+l,y)
        segment(x,y,x,y+l)
    else:
        segment(x,y,x+l,y)
        segment(x,y,x,y+l)
        fractale(x+l,y,l/2,etape-1)
        fractale(x,y+l,l/2,etape-1)
c.clear()
fractale(0,0,100,4)
c
../_images/48367b7efa4bed20bf25e31746ee54d406d1961d27e84a7207538a8fcca9822e.png