DEV Community

BC
BC

Posted on

Draw a Fibonacci Curve with Python Turtle

Just for fun:

from turtle import Turtle
from random import randint

t = Turtle()
scale = 5

def fib(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return fib(n-1) + fib(n-2)

def semi_circle(radius):
    rgb = [randint(0, 255) for i in range(3)]
    t.color(*rgb)
    t.circle(radius, 90)

for i in range(10):    
    semi_circle(fib(i) * scale)
Enter fullscreen mode Exit fullscreen mode

Result:

fibonacci curve

Top comments (0)