turtle_dragon.py

Created by ferr0fluidmann

Created on April 09, 2019

648 Bytes

Draws a dragon curve using the turtle library. Run with dragon_run().


from turtle import *

def dragon(step, angle, depth):
  commands = "RF"
  for i in range(depth):
    commands2 = ""
    for j in range(len(commands)):
      indx = len(commands)-(j+1)
      if j > 0:
        if (commands[indx] == 'F'):
          forward(step)
          commands2 += 'F'
        if (commands[indx] == 'R'):
          right(angle)
          commands2 += 'L'
        if (commands[indx] == 'L'):
          left(angle)
          commands2 += 'R'
    for c in commands2:
      commands += c

def dragon_run():
  reset()
  color('red')
  penup()
  speed(10)
  goto(-40,-40)
  left(90)
  pendown()
  dragon(6, 90, 10)