SHARE
TWEET

Koch snowflake

yiorgos Feb 20th, 2019 (edited) 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import turtle
  2. import functools
  3.  
  4. # Compute the next digit of the Thue-Morse sequence
  5. # https://oeis.org/A010060
  6. # Learn about evil and oddium numbers in the process.
  7.  
  8. def thue_morse_seq(n=0):
  9.   while True:
  10.     yield functools.reduce(lambda x, y: x + y, map(int, bin(n)[2:])) % 2
  11.     n += 1
  12.  
  13. if __name__ == "__main__":
  14.  
  15.   window = turtle.Screen()
  16.   window.bgcolor('light gray')
  17.  
  18.   pen = turtle.Turtle()
  19.   pen.speed(20)
  20.   pen.color('dark blue')
  21.   pen.pensize(1)
  22.   pen.shape('classic')
  23.   pen.penup()
  24.   pen.setpos(200, 200)
  25.   pen.pendown()
  26.  
  27.   n = thue_morse_seq(0)
  28.   while True:
  29.     if next(n) == 0:
  30.       pen.forward(2)
  31.     else:
  32.       pen.left(60)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top