Created
October 20, 2020 15:31
-
-
Save initbar/6714e5fbf6d30feaaeb6265b28666c9f to your computer and use it in GitHub Desktop.
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 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