Created
October 6, 2018 07:04
-
-
Save shivampip/447525b07ada1502ebdcc773601daed9 to your computer and use it in GitHub Desktop.
[Dragon Curve] #dragoncurve #dragon #curve #python #turtle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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