pythagoras_opgave_10.py

Created by numworks-nl

Created on May 03, 2023

677 Bytes


# tientallen fractals zijn te vinden op:
# https://pythonturtle.academy/t-square-fractal-with-python-turtle-source-code/

import turtle

turtle.speed(0)
turtle.pencolor('blue')

def stacksquares(x,y,length,n):
  if n==0: return
  stacksquares(x-length/2,y-length/2,length/2,n-1)
  stacksquares(x+length/2,y+length/2,length/2,n-1)
  stacksquares(x-length/2,y+length/2,length/2,n-1)
  stacksquares(x+length/2,y-length/2,length/2,n-1)

  turtle.up()
  turtle.goto(x-length/2,y-length/2)
  turtle.down()
  turtle.setheading(0)

  for _ in range(4):
    turtle.forward(length)
    turtle.left(90)

turtle.up()
turtle.goto(-80,-80)
stacksquares(0,0,200,7)