yiorgos icon

KochSnowflake1.py

yiorgos | PRO | 02/20/19 08:51:07 PM UTC | 0 ⭐ | 605 👁️ | Never ⏰ | []
Python |

660 B

|

None

|

0 👍

/

0 👎

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)

Comments