Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.0 kB
0
Indexable
Never
import turtle

def dragon_curve(turtle, order, length):
    if order == 0:
        turtle.forward(length)
    else:
        dragon_curve(turtle, order-1, length)
        turtle.left(90)
        anti_dragon_curve(turtle, order-1, length)
        turtle.left(-90)

def anti_dragon_curve(turtle, order, length):
    if order == 0:
        turtle.forward(length)
    else:
        turtle.left(-90)
        dragon_curve(turtle, order-1, length)
        turtle.left(90)
        anti_dragon_curve(turtle, order-1, length)

if __name__ == "__main__":
    # Setup turtle
    screen = turtle.Screen()
    screen.bgcolor("white")
    screen.title("Dragon Curve")
    dragon_turtle = turtle.Turtle()
    dragon_turtle.speed(0)
    dragon_turtle.color("black")

    order = 12  # Adjust the order for more complexity
    length = 10  # Adjust the length of each segment

    dragon_turtle.penup()
    dragon_turtle.goto(-100, 0)
    dragon_turtle.pendown()

    # Draw the dragon curve
    dragon_curve(dragon_turtle, order, length)

    screen.mainloop()