-
Notifications
You must be signed in to change notification settings - Fork 0
/
lion.py
314 lines (288 loc) · 13.5 KB
/
lion.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# -*- coding: utf-8 -*-
import turtle as tur
from math import sin, cos, pi
DRAW_SPEED = 30
PEN_SIZE = 6
WIDTH = 600
HEIGHT = 600
"""
辅助函数
"""
def linear_interp(p1, p2, t):
return p1 * (1 - t) + p2 * t
def bezier1(p1, p2, t):
return (
linear_interp(p1[0], p2[0], t),
linear_interp(p1[1], p2[1], t)
)
def bezier2(p1, p2, p3, t):
return bezier1(
bezier1(p1, p2, t),
bezier1(p2, p3, t),
t
)
def bezier3(p1, p2, p3, p4, t):
return bezier1(
bezier2(p1, p2, p3, t),
bezier2(p2, p3, p4, t),
t
)
def bezier_3(p1, p2, p3, p4):
for t in [x / 15 for x in range(0, 15 + 1)]:
x, y = bezier3(p1, p2, p3, p4, t)
tur.goto(x, y)
def p(c): # 将 SVG 坐标 c 转换为 tur 坐标
return complex(
+ c.real - WIDTH / 2,
- c.imag + HEIGHT / 2
)
def M(c): # 移动到 SVG 坐标 c
tur.goto(p(c).real, p(c).imag)
def L(start, end):
M(start)
M(end)
def C(start, control1, control2, end):
M(start)
bezier_3(
(p(start).real, p(start).imag),
(p(control1).real, p(control1).imag),
(p(control2).real, p(control2).imag),
(p(end).real, p(end).imag))
def f(sp=0j, rgb='red'):
tur.fillcolor(rgb)
M(sp)
tur.begin_fill()
nf = tur.end_fill
def pd(sp, rgb="#E4007F", bold=PEN_SIZE):
tur.color(rgb)
tur.pensize(bold)
M(sp)
tur.pendown()
def pu():
tur.penup()
tur.pensize(PEN_SIZE)
tur.color("black")
def Mv(c): # 移动到 SVG 坐标 c
tur.penup()
tur.goto(p(c).real, p(c).imag)
tur.pendown()
"""
绘图代码
"""
screen = tur.Screen()
screen.bgcolor("white")
tur.tracer(3) # 调整作画时间
tur.pensize(PEN_SIZE)
tur.speed(DRAW_SPEED)
tur.penup()
## 一笔画
pd(203.5+379.5j, rgb="black", bold=1)
C(203.5+379.5j, 197.24+399.34j, 194.05+416j, 193.5+427.5j)
C(193.5+427.5j, 192.5+448.5j, 191.5+495.5j, 200.5+519.5j)
C(200.5+519.5j, 205.81+533.66j, 206.54+549.22j, 211.5+563.5j)
C(211.5+563.5j, 212.52+566.44j, 214.72+572.08j, 212.5+577.5j)
C(212.5+577.5j, 211.49+579.96j, 210.22+580.81j, 210.5+582.5j)
C(210.5+582.5j, 211.12+586.23j, 218.46+589.01j, 224.5+588.5j)
C(224.5+588.5j, 231.72+587.89j, 238.68+583.5j, 239.5+579.5j)
C(239.5+579.5j, 247.5+540.5j, 248.71+520.13j, 270.5+516.5j)
C(270.5+516.5j, 281.5+514.67j, 293.72+528.93j, 295.5+540.5j)
C(295.5+540.5j, 297.5+553.5j, 298.07+560.37j, 300.5+572.5j)
C(300.5+572.5j, 302.5+582.5j, 313.5+588.5j, 327.5+586.5j)
C(327.5+586.5j, 329.79+586.17j, 333.5+582.5j, 330.5+578.5j)
C(330.5+578.5j, 330.5+578.5j, 330.5+566.5j, 331.5+562.5j)
C(331.5+562.5j, 333.94+552.75j, 340.5+520.5j, 341.5+507.5j)
C(341.5+507.5j, 340.84+507.27j, 339.5+506.85j, 339.5+507.5j)
C(339.5+507.5j, 339.5+511.5j, 348.5+529.5j, 360.5+545.5j)
C(360.5+545.5j, 367.5+555.5j, 374.8+561.03j, 387.5+569.5j)
C(387.5+569.5j, 388.27+571.57j, 388.51+577.5j, 392.5+577.5j)
C(392.5+577.5j, 398.5+577.5j, 405.05+586.39j, 406.5+583.5j)
C(406.5+583.5j, 408.5+579.5j, 404.5+576.5j, 404.5+573.5j)
C(404.5+573.5j, 404.5+570.5j, 394.5+566.5j, 390.5+565.5j)
C(390.5+565.5j, 386.5+565.5j, 374.86+554.97j, 363.5+539.5j)
C(363.5+539.5j, 355.62+528.77j, 346.34+510.53j, 344.5+499.5j)
C(344.5+499.5j, 343.5+493.5j, 345.45+486.98j, 347.5+466.5j)
C(347.5+466.5j, 349.5+446.5j, 346.5+394.5j, 341.5+386.5j)
C(341.5+386.5j, 339.74+383.68j, 337.8+380.37j, 331.5+377.5j)
C(331.5+377.5j, 324.5+377.5j, 308.5+378.5j, 289.5+380.5j)
C(289.5+380.5j, 267.26+382.84j, 249.69+380.73j, 238.5+378.5j)
C(238.5+378.5j, 235.42+377.89j, 210.03+372.03j, 205.5+367.5j)
C(205.5+367.5j, 203.5+365.5j, 196.5+365.5j, 196.5+360.5j)
C(196.5+360.5j, 196.5+357.5j, 202.5+359.24j, 202.5+357.5j)
C(202.5+357.5j, 202.5+354.5j, 193.26+356.45j, 194.5+351.5j)
C(194.5+351.5j, 195.5+347.5j, 200.7+351.3j, 202.5+349.5j)
C(202.5+349.5j, 204.5+347.5j, 198.5+343.5j, 200.5+340.5j)
C(200.5+340.5j, 201.49+339.01j, 205.77+342.1j, 214.5+343.5j)
C(214.5+343.5j, 218.34+344.12j, 220.48+344.01j, 222.5+343.5j)
C(222.5+343.5j, 223.72+343.19j, 229.03+341.84j, 229.5+338.5j)
C(229.5+338.5j, 229.76+336.68j, 228.56+334.5j, 227.5+334.5j)
C(227.5+334.5j, 222.5+334.5j, 225.84+339.18j, 222.5+345.5j)
C(222.5+345.5j, 220.67+348.96j, 216.68+355.19j, 214.5+354.5j)
C(214.5+354.5j, 212.98+354.02j, 212.59+350.41j, 213.5+349.5j)
C(213.5+349.5j, 215.5+347.5j, 217.85+353.29j, 223.5+353.5j)
C(223.5+353.5j, 224.64+353.54j, 226+353.01j, 226.5+351.5j)
C(226.5+351.5j, 227.5+348.5j, 227.5+348.5j, 229.5+346.5j)
C(229.5+346.5j, 230.5+345.5j, 233.34+346.13j, 234.5+347.5j)
C(234.5+347.5j, 235.63+348.85j, 235.01+351.29j, 233.5+352.5j)
C(233.5+352.5j, 231.99+353.71j, 229.8+353.52j, 228.5+352.5j)
C(228.5+352.5j, 226.02+350.55j, 228.2+346.87j, 229.5+346.5j)
C(229.5+346.5j, 230.72+346.16j, 230.48+348.79j, 233.5+349.5j)
C(233.5+349.5j, 236.82+350.28j, 241.5+346.5j, 240.5+346.5j)
C(240.5+346.5j, 240.5+346.5j, 235.5+354.5j, 236.5+355.5j)
C(236.5+355.5j, 237.5+356.5j, 241.75+354.13j, 243.5+351.5j)
C(243.5+351.5j, 245.5+348.5j, 245.5+347.5j, 245.5+347.5j)
C(245.5+347.5j, 245.5+345.5j, 244.38+351.5j, 248.5+351.5j)
C(248.5+351.5j, 253.5+351.5j, 255.5+351.5j, 256.5+350.5j)
C(256.5+350.5j, 257.66+349.34j, 254.79+346.39j, 251.5+347.5j)
C(251.5+347.5j, 248.5+348.51j, 248.55+353.71j, 250.5+355.5j)
C(250.5+355.5j, 252.29+357.15j, 255.46+356.16j, 257.5+355.5j)
C(257.5+355.5j, 266.27+352.65j, 271.5+345.5j, 271.5+345.5j)
C(271.5+345.5j, 272.5+342.5j, 265.97+354.24j, 268.5+355.5j)
C(268.5+355.5j, 272.5+357.5j, 276.5+345.5j, 275.5+347.5j)
C(275.5+347.5j, 275.5+347.5j, 272.5+359.5j, 270.5+363.5j)
C(270.5+363.5j, 269.24+366.03j, 266.12+363.63j, 266.5+362.5j)
C(266.5+362.5j, 267.4+359.79j, 276.5+357.05j, 276.5+353.5j)
C(276.5+353.5j, 276.5+352.5j, 276.5+351.5j, 277.5+349.5j)
C(277.5+349.5j, 277.5+349.5j, 278.2+347.9j, 279.5+347.5j)
C(279.5+347.5j, 280.97+347.05j, 282.83+347.92j, 283.5+349.5j)
C(283.5+349.5j, 284.13+350.98j, 283.51+352.64j, 282.5+353.5j)
C(282.5+353.5j, 280.79+354.97j, 278.5+354.5j, 277.5+353.5j)
C(277.5+353.5j, 276.5+352.5j, 276.5+350.5j, 277.5+349.5j)
C(277.5+349.5j, 278.5+350.5j, 278.5+350.5j, 280.5+350.5j)
C(280.5+350.5j, 284.5+350.5j, 286.5+346.5j, 286.5+346.5j)
C(286.5+346.5j, 285.5+345.5j, 284.5+354.5j, 286.5+354.5j)
C(286.5+354.5j, 291.5+354.5j, 290.5+347.5j, 290.5+346.5j)
C(290.5+346.5j, 290.5+346.5j, 290.79+352.79j, 291.5+353.5j)
C(291.5+353.5j, 292.5+354.5j, 295.19+354.12j, 295.5+353.5j)
C(295.5+353.5j, 296.5+351.5j, 295.5+342.75j, 295.5+344.5j)
C(295.5+344.5j, 295.5+346.5j, 298.4+345.82j, 300.5+345.5j)
C(300.5+345.5j, 301.19+345.39j, 301.68+345.12j, 301.97+344.95j)
C(301.97+344.95j, 303.82+343.89j, 305.16+341.45j, 304.5+340.5j)
C(304.5+340.5j, 304+339.78j, 302.21+339.7j, 301.5+340.5j)
C(301.5+340.5j, 301+341.06j, 301.12+341.96j, 302.5+346.5j)
C(302.5+346.5j, 303.61+350.15j, 303.96+350.96j, 303.5+351.5j)
C(303.5+351.5j, 302.48+352.71j, 298.5+351.41j, 298.5+350.5j)
C(298.5+350.5j, 298.5+349.47j, 302.72+350.28j, 306.5+346.5j)
C(306.5+346.5j, 308.5+344.5j, 310.5+342.74j, 310.5+341.5j)
C(310.5+341.5j, 310.5+340.5j, 307.39+340.14j, 306.5+341.5j)
C(306.5+341.5j, 305.21+343.47j, 307.36+347.23j, 309.5+347.5j)
C(309.5+347.5j, 311.97+347.81j, 314.06+343.42j, 314.5+342.5j)
C(314.5+342.5j, 317.15+336.94j, 314.98+330.5j, 314.5+330.5j)
C(314.5+330.5j, 311.5+330.5j, 312.5+344.5j, 316.5+344.5j)
C(316.5+344.5j, 319.5+344.5j, 319.5+338.5j, 320.5+336.5j)
C(320.5+336.5j, 322.74+332.03j, 322.5+325.5j, 320.5+325.5j)
C(320.5+325.5j, 317.5+325.5j, 318.24+330.74j, 319.5+335.5j)
C(319.5+335.5j, 320.83+340.52j, 324.39+342.55j, 323.5+344.5j)
C(323.5+344.5j, 322.98+345.65j, 320.56+345.56j, 319.5+344.5j)
C(319.5+344.5j, 318.5+343.5j, 318.5+337.5j, 320.5+336.5j)
C(320.5+336.5j, 326.91+333.3j, 329.64+330.89j, 332.5+328.5j)
C(332.5+328.5j, 335.54+325.97j, 336.13+323.92j, 338.5+323.5j)
C(338.5+323.5j, 341.25+323.02j, 342.47+325.81j, 345.5+325.5j)
C(345.5+325.5j, 349.15+325.13j, 352.21+320.57j, 351.5+319.5j)
C(351.5+319.5j, 350.88+318.57j, 346.8+319.39j, 344.5+321.5j)
C(344.5+321.5j, 339.78+325.83j, 340.21+337.69j, 345.5+343.5j)
C(345.5+343.5j, 355.5+354.5j, 388.5+355.5j, 400.5+335.5j)
C(400.5+335.5j, 401.43+333.94j, 405.5+323.5j, 403.5+317.5j)
C(403.5+317.5j, 401.58+311.73j, 391.27+309.43j, 390.5+312.5j)
C(390.5+312.5j, 389.5+316.5j, 398.5+317.5j, 403.5+317.5j)
C(403.5+317.5j, 410.5+317.5j, 439.52+312.44j, 447.5+288.5j)
C(447.5+288.5j, 454.5+267.5j, 449.79+258.28j, 441.5+247.5j)
C(441.5+247.5j, 431.5+234.5j, 410.13+235.53j, 409.5+242.5j)
C(409.5+242.5j, 409.35+244.2j, 409.64+245.56j, 410.32+246.65j)
C(410.32+246.65j, 414.58+253.52j, 431.18+251.91j, 441.5+247.5j)
C(441.5+247.5j, 453.43+242.41j, 467.2+229.2j, 467.5+210.5j)
C(467.5+210.5j, 467.77+193.58j, 456.96+175.19j, 439.5+171.5j)
C(439.5+171.5j, 420.96+167.58j, 398.25+180.38j, 403.5+186.5j)
C(403.5+186.5j, 409.5+193.5j, 429.5+184.5j, 439.5+171.5j)
C(439.5+171.5j, 449.19+158.9j, 461.5+135.5j, 444.5+114.5j)
C(444.5+114.5j, 427.56+93.58j, 410.41+95.15j, 390.5+102.5j)
C(390.5+102.5j, 377.21+107.4j, 365.97+118.11j, 370.5+121.5j)
C(370.5+121.5j, 374.5+124.5j, 386.14+115.57j, 390.5+102.5j)
C(390.5+102.5j, 397.5+81.5j, 400.5+59.5j, 384.5+45.5j)
C(384.5+45.5j, 371.19+33.85j, 355.31+39.88j, 344.5+48.5j)
C(344.5+48.5j, 332.72+57.89j, 324.5+73.5j, 331.5+76.5j)
C(331.5+76.5j, 337.31+78.99j, 345.59+62.66j, 344.5+48.5j)
C(344.5+48.5j, 343.5+35.5j, 335.75+16.91j, 317.5+16.5j)
C(317.5+16.5j, 302.54+16.16j, 288.57+30.12j, 286.5+41.5j)
C(286.5+41.5j, 284.5+52.5j, 286.5+75.5j, 295.5+71.5j)
C(295.5+71.5j, 301.63+68.78j, 294.85+52.05j, 286.5+41.5j)
C(286.5+41.5j, 267.5+17.5j, 238.92+9.36j, 208.5+19.5j)
C(208.5+19.5j, 184.5+27.5j, 174.5+45.5j, 181.5+78.5j)
C(181.5+78.5j, 186.71+103.04j, 212.77+122.67j, 218.5+113.5j)
C(218.5+113.5j, 223.5+105.5j, 200.5+81.5j, 181.5+78.5j)
C(181.5+78.5j, 158.49+74.87j, 120.15+85.46j, 112.5+113.5j)
C(112.5+113.5j, 109.5+124.5j, 116.05+143.32j, 134.5+156.5j)
C(134.5+156.5j, 155.5+171.5j, 181.46+173.17j, 184.5+159.5j)
C(184.5+159.5j, 186.5+150.5j, 161.5+139.5j, 134.5+156.5j)
C(134.5+156.5j, 113.14+169.95j, 102.72+188.47j, 105.5+213.5j)
C(105.5+213.5j, 107.5+231.5j, 120.12+244.79j, 140.5+250.5j)
C(140.5+250.5j, 165.5+257.5j, 179.14+245.54j, 178.5+238.5j)
C(178.5+238.5j, 177.5+227.5j, 152.5+231.5j, 140.5+250.5j)
C(140.5+250.5j, 129.69+267.61j, 124.78+296.54j, 141.5+311.5j)
C(141.5+311.5j, 160.5+328.5j, 188.81+318.81j, 197.5+304.5j)
C(197.5+304.5j, 201.28+298.27j, 201.5+288.5j, 198.5+288.5j)
C(198.5+288.5j, 194.38+288.5j, 191.1+299.7j, 197.5+304.5j)
C(197.5+304.5j, 216.58+318.81j, 268.18+326.21j, 305.5+316.5j)
C(305.5+316.5j, 317.17+313.47j, 327.5+306.5j, 327.5+303.5j)
C(327.5+303.5j, 327.5+292.45j, 328.4+286.81j, 335.5+268.5j)
C(335.5+268.5j, 335.73+267.9j, 339.37+258.76j, 347.38+250.05j)
C(347.38+250.05j, 350.15+247.04j, 352.1+245.53j, 354.5+244.5j)
C(354.5+244.5j, 361.52+241.49j, 369.53+243.8j, 369.5+244.5j)
C(369.5+244.5j, 369.47+245.2j, 361.28+247.11j, 354.5+244.5j)
C(354.5+244.5j, 344.46+240.63j, 338.9+227.4j, 338.5+216.5j)
C(338.5+216.5j, 338.12+206.13j, 342.23+192.45j, 351.5+188.5j)
C(351.5+188.5j, 357.84+185.8j, 365.51+188.11j, 365.5+188.5j)
C(365.5+188.5j, 365.49+188.88j, 358.31+190.12j, 351.5+188.5j)
C(351.5+188.5j, 335.88+184.78j, 326+166.83j, 325.5+155.5j)
C(325.5+155.5j, 325.33+151.61j, 326.19+148.11j, 326.19+148.11j)
C(326.19+148.11j, 327.41+143.13j, 329.82+139.96j, 332.5+136.5j)
C(332.5+136.5j, 335.47+132.67j, 339.01+128.1j, 342.28+128.78j)
C(342.28+128.78j, 342.56+128.84j, 343.33+129j, 343.5+129.5j)
C(343.5+129.5j, 344.01+131.06j, 338.41+135.12j, 332.5+136.5j)
C(332.5+136.5j, 329.63+137.17j, 326.61+136.83j, 320.58+136.16j)
C(320.58+136.16j, 315.41+135.58j, 311.51+135.12j, 306.5+133.5j)
C(306.5+133.5j, 302.93+132.34j, 300.31+131.5j, 297.3+129.48j)
C(297.3+129.48j, 295.34+128.17j, 288.47+123.57j, 287.5+116.5j)
C(287.5+116.5j, 286.72+110.79j, 290.07+105.38j, 290.5+105.5j)
C(290.5+105.5j, 290.92+105.62j, 290.68+111.61j, 287.5+116.5j)
C(287.5+116.5j, 283.12+123.24j, 275.05+125.02j, 272.52+125.59j)
C(272.52+125.59j, 268.74+126.43j, 262.59+127.79j, 258.5+124.5j)
C(258.5+124.5j, 253.92+120.82j, 253.71+112.76j, 254.5+112.5j)
C(254.5+112.5j, 255.26+112.25j, 259.55+118.51j, 258.5+124.5j)
C(258.5+124.5j, 257.5+130.19j, 252.06+133.54j, 250.5+134.5j)
C(250.5+134.5j, 242.46+139.45j, 233.58+137.11j, 231.5+136.5j)
## 左眼
Mv(211.5+215.5j)
C(211.5+215.5j, 210.76+219.54j, 213.75+223.25j, 217.5+223.5j)
C(217.5+223.5j, 221.19+223.74j, 224.62+220.55j, 224.5+216.5j)
## 右眼
Mv(289.5+218.5j)
C(289.5+218.5j, 289.38+222.46j, 292.06+225.83j, 295.5+226.5j)
C(295.5+226.5j, 299.55+227.29j, 303.93+224.21j, 304.5+219.5j)
## 鼻子和嘴
Mv(205.5+265.5j)
C(205.5+265.5j, 205.77+265.6j, 209.73+267.27j, 212.5+264.5j)
C(212.5+264.5j, 215.5+261.5j, 215.5+259.87j, 215.5+259.5j)
C(215.5+259.5j, 215.5+256.5j, 215.5+247.5j, 215.5+247.5j)
C(215.5+247.5j, 215.5+247.5j, 204.5+242.5j, 205.5+238.5j)
C(205.5+238.5j, 206.46+234.65j, 228.15+233.8j, 229.5+236.5j)
C(229.5+236.5j, 231.5+240.5j, 215.5+247.5j, 215.5+247.5j)
L(215.5+247.5j, 215.5+259.5j)
C(215.5+259.5j, 217.09+264.26j, 218.39+267.06j, 220.61+268.65j)
C(220.61+268.65j, 223.77+270.91j, 227.22+270.64j, 229.5+270.5j)
C(229.5+270.5j, 235.43+270.14j, 239.64+267.06j, 241.5+265.5j)
L(241.5+265.5j, 241.5+263.5j)
C(241.5+263.5j, 242.5+255.43j, 248.55+251.15j, 249.5+250.5j)
C(249.5+250.5j, 248.55+251.15j, 242.5+255.43j, 241.5+263.5j)
C(241.5+263.5j, 240.35+272.76j, 246.86+278.91j, 247.5+279.5j)
## 手
Mv(326.5+305.5j)
C(326.5+305.5j, 329.5+304.5j, 331.98+304.34j, 332.5+305.5j)
C(332.5+305.5j, 333.23+307.13j, 329.69+309.69j, 330.5+310.5j)
C(330.5+310.5j, 332.5+312.5j, 336.5+307.5j, 338.5+309.5j)
C(338.5+309.5j, 340.5+311.5j, 332.99+316j, 334.5+317.5j)
C(334.5+317.5j, 335.6+318.59j, 339.38+315.52j, 340.5+316.5j)
C(340.5+316.5j, 341.31+317.21j, 341.5+319.5j, 338.5+323.5j)
pu()
Mv(203.5+379.5j)
#tur.hideturtle() # 隐藏乌龟图标
tur.update()