-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path希尔伯特曲线.py
53 lines (50 loc) · 1.2 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
# -*- coding: utf-8 -*-
# Time : 2019/4/5 22:12
# Author : Mifen
# Email : [email protected]
# Github : https://github.com/Amd794
from turtle import *
import random
length = 10
angle = 90
setup(1280,720)
up()
color("#262626;")
goto(-600,300)
write('Author:Mifen',font=("微软雅黑", 18))
goto(-600,250)
write('E-mail :[email protected]',font=("微软雅黑", 18))
goto(-600, 200)
write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18))
goto(-640,-360)
down()
def draw_path(path):
for symbol in path:
if symbol == 'f':
colormode(255)
color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
fd(length)
elif symbol == '+':
lt(angle)
elif symbol == '-':
rt(angle)
def apply_path(rules,path):
lit = [x for x in path]
for i in range(len(lit)):
symbol = lit[i]
if symbol == 'x':
lit[i] = rules[symbol]
elif symbol == 'y':
lit[i] = rules[symbol]
path = ''.join(lit)
return path
rules = {
'x':'+yf-xfx-fy+',
'y':'-xf+yfy+fx-'
}
path = 'x'
speed(0)
for i in range(7):
path = apply_path(rules,path)
draw_path(path)
done()