Skip to content

Instantly share code, notes, and snippets.

@shivampip
Created October 6, 2018 07:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivampip/447525b07ada1502ebdcc773601daed9 to your computer and use it in GitHub Desktop.
Save shivampip/447525b07ada1502ebdcc773601daed9 to your computer and use it in GitHub Desktop.
[Dragon Curve] #dragoncurve #dragon #curve #python #turtle
import turtle as t
import math
n= 21 # Number of folds
step= 1 # Step length
l= 2**n - 1
a= [0]*l
def fold(m, start, end, dir):
if(m<=n):
c= start + math.floor((end - start) / 2)
a[c]= dir
#print(a)
fold(m+1, start, c-1, 0)
fold(m+1, c+1, end, 1)
fold(1, 0, l, 0)
t.left(0)
t.speed(0)
t.forward(step)
for i in range(l):
if(a[i]==0):
t.left(90)
else:
t.right(90)
t.forward(step)
while(True):
t.left(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment