最近有个问题刷爆朋友圈——啥是佩奇?
如果问家里的小朋友,TA会告诉你,佩奇是猪!
是的,就是那只粉红色的可爱小猪。。。
想起在博客园nowgood的博客里看到过网友江城青椒肉丝提供的用Python的小海龟绘制佩奇的程序,于是也绘制了一个,与大家分享!
绘制佩奇的Python脚本如下:
1# coding:utf-8
2import turtle as t
3# 绘制小猪佩奇
4# =======================================
5
6t.pensize(4)
7t.hideturtle()
8t.colormode(255)
9t.color((255, 155, 192), "pink")
10t.setup(840, 500)
11t.speed(10)
12
13# 鼻子
14t.pu()
15t.goto(-100,100)
16t.pd()
17t.seth(-30)
18t.begin_fill()
19a = 0.4
20for i in range(120):
21 if 0 <= i < 30 or 60 <= i < 90:
22 a = a+0.08
23 t.lt(3) # 向左转3度
24 t.fd(a) # 向前走a的步长
25 else:
26 a = a-0.08
27 t.lt(3)
28 t.fd(a)
29 t.end_fill()
30
31t.pu()
32t.seth(90)
33t.fd(25)
34t.seth(0)
35t.fd(10)
36t.pd()
37t.pencolor(255, 155, 192)
38t.seth(10)
39t.begin_fill()
40t.circle(5)
41t.color(160, 82, 45)
42t.end_fill()
43
44t.pu()
45t.seth(0)
46t.fd(20)
47t.pd()
48t.pencolor(255, 155, 192)
49t.seth(10)
50t.begin_fill()
51t.circle(5)
52t.color(160, 82, 45)
53t.end_fill()
54
55# 头
56t.color((255, 155, 192), "pink")
57t.pu()
58t.seth(90)
59t.fd(41)
60t.seth(0)
61t.fd(0)
62t.pd()
63t.begin_fill()
64t.seth(180)
65t.circle(300, -30)
66t.circle(100, -60)
67t.circle(80, -100)
68t.circle(150, -20)
69t.circle(60, -95)
70t.seth(161)
71t.circle(-300, 15)
72t.pu()
73t.goto(-100, 100)
74t.pd()
75t.seth(-30)
76a = 0.4
77for i in range(60):
78 if 0 <= i < 30 or 60 <= i <90:
79 a = a+0.08
80 t.lt(3) # 向左转3度
81 t.fd(a) # 向前走a的步长
82 else:
83 a = a-0.08
84 t.lt(3)
85 t.fd(a)
86 t.end_fill()
87
88# 耳朵
89t.color((255, 155, 192), "pink")
90t.pu()
91t.seth(90)
92t.fd(-7)
93t.seth(0)
94t.fd(70)
95t.pd()
96t.begin_fill()
97t.seth(100)
98t.circle(-50, 50)
99t.circle(-10, 120)
100t.circle(-50, 54)
101t.end_fill()
102
103t.pu()
104t.seth(90)
105t.fd(-12)
106t.seth(0)
107t.fd(30)
108t.pd()
109t.begin_fill()
110t.seth(100)
111t.circle(-50, 50)
112t.circle(-10, 120)
113t.circle(-50, 56)
114t.end_fill()
115
116#眼睛
117t.color((255, 155, 192), "white")
118t.pu()
119t.seth(90)
120t.fd(-20)
121t.seth(0)
122t.fd(-95)
123t.pd()
124t.begin_fill()
125t.circle(15)
126t.end_fill()
127
128t.color("black")
129t.pu()
130t.seth(90)
131t.fd(12)
132t.seth(0)
133t.fd(-3)
134t.pd()
135t.begin_fill()
136t.circle(3)
137t.end_fill()
138
139t.color((255, 155, 192), "white")
140t.pu()
141t.seth(90)
142t.fd(-25)
143t.seth(0)
144t.fd(40)
145t.pd()
146t.begin_fill()
147t.circle(15)
148t.end_fill()
149
150t.color("black")
151t.pu()
152t.seth(90)
153t.fd(12)
154t.seth(0)
155t.fd(-3)
156t.pd()
157t.begin_fill()
158t.circle(3)
159t.end_fill()
160
161# 腮
162t.color((255, 155, 192))
163t.pu()
164t.seth(90)
165t.fd(-95)
166t.seth(0)
167t.fd(65)
168t.pd()
169t.begin_fill()
170t.circle(30)
171t.end_fill()
172
173# 嘴
174t.color(239, 69, 19)
175t.pu()
176t.seth(90)
177t.fd(15)
178t.seth(0)
179t.fd(-100)
180t.pd()
181t.seth(-80)
182t.circle(30, 40)
183t.circle(40, 80)
184
185# 身体
186t.color("red", (255, 99, 71))
187t.pu()
188t.seth(90)
189t.fd(-20)
190t.seth(0)
191t.fd(-78)
192t.pd()
193t.begin_fill()
194t.seth(-130)
195t.circle(100,10)
196t.circle(300,30)
197t.seth(0)
198t.fd(230)
199t.seth(90)
200t.circle(300,30)
201t.circle(100,3)
202t.color((255,155,192),(255,100,100))
203t.seth(-135)
204t.circle(-80,63)
205t.circle(-150,24)
206t.end_fill()
207
208# 手
209t.color((255,155,192))
210t.pu()
211t.seth(90)
212t.fd(-40)
213t.seth(0)
214t.fd(-27)
215t.pd()
216t.seth(-160)
217t.circle(300,15)
218t.pu()
219t.seth(90)
220t.fd(15)
221t.seth(0)
222t.fd(0)
223t.pd()
224t.seth(-10)
225t.circle(-20,90)
226
227t.pu()
228t.seth(90)
229t.fd(30)
230t.seth(0)
231t.fd(237)
232t.pd()
233t.seth(-20)
234t.circle(-300,15)
235t.pu()
236t.seth(90)
237t.fd(20)
238t.seth(0)
239t.fd(0)
240t.pd()
241t.seth(-170)
242t.circle(20,90)
243
244# 脚
245t.pensize(10)
246t.color((240,128,128))
247t.pu()
248t.seth(90)
249t.fd(-75)
250t.seth(0)
251t.fd(-180)
252t.pd()
253t.seth(-90)
254t.fd(40)
255t.seth(-180)
256t.color("black")
257t.pensize(15)
258t.fd(20)
259
260t.pensize(10)
261t.color((240, 128, 128))
262t.pu()
263t.seth(90)
264t.fd(40)
265t.seth(0)
266t.fd(90)
267t.pd()
268t.seth(-90)
269t.fd(40)
270t.seth(-180)
271t.color("black")
272t.pensize(15)
273t.fd(20)
274
275# 尾巴
276t.pensize(4)
277t.color((255, 155, 192))
278t.pu()
279t.seth(90)
280t.fd(70)
281t.seth(0)
282t.fd(95)
283t.pd()
284t.seth(0)
285t.circle(70, 20)
286t.circle(10, 330)
287t.circle(70, 30)
288t.done()
—END—