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)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.