-
Notifications
You must be signed in to change notification settings - Fork 0
/
8 - Snowflake Fractal.py
49 lines (37 loc) · 1.03 KB
/
8 - Snowflake Fractal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Tara Moses
#Assignment 8: Snowflake Fractal
#February 4, 2013
#1. Program draws a snowflake fractal depending on the user-specified fractal order.
#2. Program fills the snowflake with a certain user-specified color.
import turtle,Tkinter
order=int(raw_input("What order fractal would you like? "))
snowflake_color=raw_input("What color would you like it to be? ")
screen_width=turtle.window_width()-50.0
screen_height=turtle.window_height()-50.0
top_corner_x=-1*(screen_width/2.0)
top_corner_y=screen_height/2.0
directions="srsrs"
length=300.0
turtle.speed(0)
if order>4:
turtle.tracer(3)
turtle.dot()
turtle.up()
turtle.goto(-150, 90)
turtle.down()
turtle.fillcolor(snowflake_color)
turtle.fill(True)
for i in range(order):
if order==0:
break
directions=directions.replace("s"," slsrsls ")
length=length/3.0
for letter in directions:
if letter=="s":
turtle.forward(length)
elif letter=="r":
turtle.right(120.0)
elif letter=="l":
turtle.left(60.0)
turtle.fill(False)
turtle.mainloop()