-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path科赫雪花.py
71 lines (65 loc) · 1.21 KB
/
科赫雪花.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import turtle as t
from turtle import *
import random
def draw_path(path):
t.colormode(255)
t.color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
for symbol in path:
if symbol == 'F':
forward(length)
elif symbol == '-':
right(angle)
elif symbol == '+':
left(angle)
def apply_rule(path):
rule = 'F+F--F+F'
return path.replace('F',rule)
length = .5
angle = 60
setup(1280,720)
bgcolor('black')
up()
color("#0fe6ca")
goto(-600, 300)
write('Author:Mifen', font=("微软雅黑", 18))
goto(-600, 250)
write('E-mail :[email protected]', font=("微软雅黑", 18))
goto(0,0)
down()
path = 'F--F--F'
speed(0)
up()
goto(-440,-250)
down()
for i in range(5):
path = apply_rule(path)
draw_path(path)
draw_path(path)
draw_path(path)
a,b = pos()
for i in range(3):
up()
a += 250
goto(a,b)
down()
draw_path(path)
draw_path(path)
draw_path(path)
b += 220
for i in range(2):
up()
a -= 250
goto(a,b)
down()
draw_path(path)
draw_path(path)
draw_path(path)
b += 220
for i in range(2):
draw_path(path)
draw_path(path)
draw_path(path)
up()
a += 130
goto(a,b)
down()