Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import turtle as tut
- import random as rand
- def main():
- fractal = buildfractal(getword(), getit())
- drawfractal(fractal)
- return 0
- def buildfractal(word, it):
- rand.seed(word)
- fractal = []
- for i, letter in enumerate(word):
- fractal.append((rand.random()*100+1, rand.random()*360))
- if i > len(word)//2 + len(word)%2:
- fractal.append(fractal[len(word)-i-1])
- newfractal = []
- for i in range(it):
- newfractal+=fractal
- return newfractal
- def drawfractal(fractal):
- # Create window
- tw = tut.Screen()
- # Turn Off Draw Mode
- tut.speed(0)
- tut.hideturtle()
- for a,b in fractal:
- tut.forward(a)
- tut.left(b)
- tut.up()
- # Wait for the user to turn off
- tw = tut.Screen()
- tut.exitonclick()
- def getword():
- x = 0
- while not isalphas(x):
- x = input("Write your word here: ")
- return x
- def isalphas(a):
- if not type(a) is str:
- return False
- for letter in a:
- if not letter.isalpha():
- return False
- return True
- def getit():
- x = input("Iterations: ")
- if not x.isnumeric():
- return getit()
- return int(x)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement