Skip to content

Instantly share code, notes, and snippets.

@chrishamant
Forked from fogleman/dragon.py
Created February 26, 2016 07:13
Show Gist options
  • Save chrishamant/075dfd461f0b66b6caee to your computer and use it in GitHub Desktop.
Save chrishamant/075dfd461f0b66b6caee to your computer and use it in GitHub Desktop.
Dragon Curve with Turtle Graphics (Python)
import turtle
def turn(i):
left = (((i & -i) << 1) & i) != 0
return 'L' if left else 'R'
def curve(iteration):
return ''.join([turn(i + 1) for i in range(2 ** iteration - 1)])
if __name__ == '__main__':
turtle.showturtle()
turtle.hideturtle()
turtle.speed(0)
i = 1
while True:
if turn(i) == 'L':
turtle.circle(-4, 90, 36)
else:
turtle.circle(4, 90, 36)
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment