Search code examples
pythonrecursionturtle-graphicsfractals

Turtle Graphics with Recursion


I need to draw a shape using recursion and turtle graphics.

I'm more of a looper and rarely ever use recursion, so some help here with this would be nice. Not even sure where to start.

The shape just needs to be cool looking.


Solution

  • Without any parametrization, here a beginning:

    import time
    from turtle import *
    
    def recurse(n):
        if n>0:
            left(10)
            forward(5)
            recurse(n-1)
    
    recurse(20)
    time.sleep(5)
    

    When you create recursive function, you need to have a stop criterion that effectively guaranties your program will exit at some point.