Skip to content

Instantly share code, notes, and snippets.

@kkarimi
Created July 22, 2012 10:19
Show Gist options
  • Save kkarimi/3159181 to your computer and use it in GitHub Desktop.
Save kkarimi/3159181 to your computer and use it in GitHub Desktop.
pythagoras tree
import turtle
t = turtle.Pen()
t.tracer(500)
LIMIT = 12
SCALAR = 0.5 * (2 ** 0.5)
def drawTree(size, depth):
drawSquare(size, depth / float(LIMIT))
if depth + 1 <= LIMIT:
t.left(90)
t.forward(size)
t.right(45)
drawTree(size * SCALAR, depth + 1)
t.forward(size * SCALAR)
t.right(90)
drawTree(size * SCALAR, depth + 1)
t.left(90)
t.backward(size * SCALAR)
t.left(45)
t.backward(size)
t.right(90)
def drawSquare(sideLength, darkness):
# t.fillcolor(1.0 - darkness, 0.5, 1.0 - darkness)
t.fill(True)
for i in range(4):
t.forward(sideLength)
t.left(90)
t.fill(False)
t.up(); t.goto(-100, -350); t.down()
drawTree(170.0, 0)
raw_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment