Advertisement
capodeicapi

wiskundekunst

Feb 2nd, 2022 (edited)
1,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import turtle  
  2. import math
  3.  
  4. def fractal(aturt, depth, maxdepth):  
  5.    if depth > maxdepth:  
  6.      return  
  7.    length = 180*((math.sqrt(2)/2)**depth)  
  8.    anotherturt = aturt.clone()  
  9.    aturt.forward(length)  
  10.    aturt.left(45)  
  11.    fractal(aturt, depth+1, maxdepth)  
  12.    anotherturt.right(90)  
  13.    anotherturt.forward(length)  
  14.    anotherturt.left(90)  
  15.    anotherturt.forward(length)  
  16.    if depth != maxdepth:  
  17.      turt3 = anotherturt.clone()  
  18.      turt3.left(45)  
  19.      turt3.forward(180*((math.sqrt(2)/2)**(1+depth)))  
  20.      turt3.right(90)  
  21.      fractal(turt3, depth+1, maxdepth)  
  22.    anotherturt.left(90)  
  23.    anotherturt.forward(length)  
  24.  
  25. def draw_fractal():  
  26.    window = turtle.Screen()  
  27.    turt = turtle.Turtle()  
  28.    turt.hideturtle()  
  29.    turt.penup()  
  30.    turt.goto(-75, -225)  
  31.    turt.pendown()  
  32.    turt.speed(0)  
  33.    turt.left(90)  
  34.    #change the second argument to get a bigger tree!
  35.    fractal(turt, 1, 2)  
  36.    window.exitonclick()  
  37.  
  38. draw_fractal()  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement