Created
August 3, 2020 11:55
-
-
Save umcconnell/93f865c8d3a1702a79f1629ff30d9a52 to your computer and use it in GitHub Desktop.
Draw the fibonacci spiral with Python turtle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import turtle | |
parser = argparse.ArgumentParser(description='Draw the fibonacci spiral') | |
parser.add_argument('n', type=int, help='Length of fibonacci sequence') | |
parser.add_argument('-s', '--scale', type=int, default=1) | |
parser.add_argument('--speed', type=int, default=6, help='Turtle speed') | |
args = parser.parse_args() | |
def fib(n): | |
a, b = 1, 1 | |
for _ in range(n): | |
yield a | |
a, b = b, a+b | |
turtle.speed(args.speed) | |
turtle.right(90) | |
for n in fib(args.n): | |
turtle.circle(n*args.scale, 90) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please give more details on what is not working and what environment you're using? Any kind of error message might be helpful.