Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import turtle as tut
  3. import random as rand
  4.  
  5. def main():
  6. fractal = buildfractal(getword(), getit())
  7. drawfractal(fractal)
  8. return 0
  9.  
  10. def buildfractal(word, it):
  11. rand.seed(word)
  12. fractal = []
  13. for i, letter in enumerate(word):
  14. fractal.append((rand.random()*100+1, rand.random()*360))
  15. if i > len(word)//2 + len(word)%2:
  16. fractal.append(fractal[len(word)-i-1])
  17.  
  18. newfractal = []
  19. for i in range(it):
  20. newfractal+=fractal
  21. return newfractal
  22.  
  23. def drawfractal(fractal):
  24. # Create window
  25. tw = tut.Screen()
  26.  
  27. # Turn Off Draw Mode
  28. tut.speed(0)
  29.  
  30. tut.hideturtle()
  31. for a,b in fractal:
  32. tut.forward(a)
  33. tut.left(b)
  34.  
  35. tut.up()
  36. # Wait for the user to turn off
  37. tw = tut.Screen()
  38. tut.exitonclick()
  39.  
  40. def getword():
  41. x = 0
  42. while not isalphas(x):
  43. x = input("Write your word here: ")
  44. return x
  45.  
  46. def isalphas(a):
  47. if not type(a) is str:
  48. return False
  49. for letter in a:
  50. if not letter.isalpha():
  51. return False
  52. return True
  53.  
  54. def getit():
  55. x = input("Iterations: ")
  56. if not x.isnumeric():
  57. return getit()
  58. return int(x)
  59.  
  60. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement