-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path月亮代表我的心.py
123 lines (107 loc) · 2.51 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
# Time : 2019/4/6 22:45
# Author : Mifen
# Email : [email protected]
# Github : https://github.com/Amd794
from turtle import *
import time
import turtle as t
def gotopos(x, y):
up()
goto(x, y)
down()
ht()
def author():
pensize(2)
gotopos(610, -315)
lt(-90)
fd(80)
pensize(1)
lt(-270)
gotopos(525, -330)
color("#772a2b")
write("Mifen", font=("华文隶书", 24))
gotopos(409, -360)
write("[email protected]", font=("华文隶书", 18))
gotopos(250, -390)
write("https://github.com/Amd794/Python123", font=("华文隶书", 18))
def apply_rules(path, rules):
L = [_ for _ in path]
for i in range(len(L)):
symbol = L[i]
if symbol == 'F':
L[i] = rules[symbol]
if symbol == 'X':
L[i] = rules[symbol]
path = ''.join(L)
return path
def draw_path(path):
posList, angleList = [], []
for symbol in path:
if symbol == 'F':
t.forward(length)
elif symbol == '+':
t.left(angle)
elif symbol == '-':
t.rt(angle)
elif symbol == '[':
posList.append(t.pos())
angleList.append(t.heading())
elif symbol == 'a':
t.pensize(3)
t.color("#867b68")
elif symbol == 'b':
t.pensize(2)
t.color("#867b68")
elif symbol == 'c':
t.pensize(2)
t.color("#867b68")
elif symbol == ']':
t.up()
t.home()
t.goto(posList.pop())
t.left(angleList.pop())
t.down()
def writez(x, y, str_, size=56, font="华文行楷"):
gotopos(x, y)
write(str_, font=(font, size))
setup(1280, 800)
speed(5)
bgcolor("#9c917f")
color("#afa697")
begin_fill()
gotopos(0, -400)
circle(400)
end_fill()
author()
color("#7d776d")
s = "愿天化作比翼鸟"
s2 = "在地愿为连理枝"
for i in range(len(s)):
writez(560, 350 - i * 50, s[i], 36)
for i in range(len(s2)):
writez(460, 350 - i * 50, s2[i], 36)
color("#888475")
writez(-50, 100, "我")
writez(-50, 40, "的")
writez(-160, 0, "心", 96)
writez(-50, 0, "月", 176)
writez(33, -30, "代", 62)
writez(-18, -95, "表", 78)
writez(-213, -210, "亮", 196)
gotopos(249, -26)
color("#867b68")
speed(0)
gotopos(-650, -100)
length = 6
path = 'F'
angle = 27
rules = {
'F': 'aFF[b-F++F][c+F--F]c++F--F',
'X': 'aFF+[b+F]+[c-F]'
}
for _ in range(4):
path = apply_rules(path, rules)
draw_path(path)
gotopos(570, -330)
done()