Skip to content

Instantly share code, notes, and snippets.

@adusak
Last active August 29, 2015 14:19
Show Gist options
  • Save adusak/912bdcda6d0b9196dc72 to your computer and use it in GitHub Desktop.
Save adusak/912bdcda6d0b9196dc72 to your computer and use it in GitHub Desktop.
Square fractal
from math import tan, radians, sqrt
from python.common.Turtle import Turtle
def squares(depth=50, angle=86, size=500):
t = Turtle()
length = size
for i in range(depth):
for _ in range(4):
t.forward(length)
t.right(90)
movebit = length * tan(radians(angle)) / (1 + tan(radians(angle)))
length = sqrt((length - movebit) ** 2 + movebit ** 2)
t.forward(movebit)
t.right(angle)
t.export("squares")
squares(angle=70, size=900)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment