Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import turtle
def fib():
i, j = 0, 1
yield i
while True:
i, j = j, i + j
yield i
if __name__ == "__main__":
limit = 1_000_000
rate = 0.001
f = fib()
t = turtle.Turtle()
t.hideturtle()
t.speed("fastest")
# slow impl
# n = next(f)
# for i in range(5000):
# t.forward(rate)
# if i >= n:
# n = next(f)
# t.right(90)
# t.forward(rate)
# faster impl
t = turtle.Turtle()
t.hideturtle()
f = fib()
# find sequences until limit
for seq in f:
if seq > limit:
break
t.forward(rate * seq)
t.right(90)
t.getscreen()._root.mainloop()
t.done()
# t.getscreen()
# t.getcanvas().postscript(file="test.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment