Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import functools
- # Compute the next digit of the Thue-Morse sequence
- # https://oeis.org/A010060
- # Learn about evil and oddium numbers in the process.
- def thue_morse_seq(n=0):
- while True:
- yield functools.reduce(lambda x, y: x + y, map(int, bin(n)[2:])) % 2
- n += 1
- if __name__ == "__main__":
- window = turtle.Screen()
- window.bgcolor('light gray')
- pen = turtle.Turtle()
- pen.speed(20)
- pen.color('dark blue')
- pen.pensize(1)
- pen.shape('classic')
- pen.penup()
- pen.setpos(200, 200)
- pen.pendown()
- n = thue_morse_seq(0)
- while True:
- if next(n) == 0:
- pen.forward(2)
- else:
- pen.left(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement