-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDragon curve.py
55 lines (50 loc) · 1.2 KB
/
Dragon curve.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
# -*- coding: utf-8 -*-
# Time : 2019/4/5 22:18
# Author : Mifen
# Email : [email protected]
# Github : https://github.com/Amd794
from turtle import *
length = 5
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(300,-100)
down()
def draw_path(path):
for symbol in path:
if symbol == 'f':
import random
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':'x+yf+',
'y':'-fx-y'
}
path = 'fx'
speed(0)
for i in range(13):
path = apply_path(rules,path)
draw_path(path)
done()