Skip to content

Commit e33a98f

Browse files
committed
submit code
1 parent 4026bd2 commit e33a98f

File tree

3 files changed

+848
-1
lines changed

3 files changed

+848
-1
lines changed

chaoxi/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Python技术 公众号文章代码库
88
![](http://favorites.ren/assets/images/python.jpg)
99

1010
## 实例代码
11-
opencv_img
11+
12+
[用 Python 给小表弟画皮卡丘!](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/pkq) 用 Python 给小表弟画皮卡丘!
1213

1314
[惊艳!利用 Python 图像处理绘制专属头像](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/opencv_img) 惊艳!利用 Python 图像处理绘制专属头像
1415

chaoxi/pkq/pikaqiu1.py

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
import turtle as t
2+
3+
def face(x, y):
4+
"""画脸"""
5+
t.begin_fill()
6+
t.penup()
7+
# 将海龟移动到指定的坐标
8+
t.goto(x, y)
9+
t.pendown()
10+
# 设置海龟的方向
11+
t.setheading(40)
12+
13+
t.circle(-150, 69)
14+
t.fillcolor("#FBD624")
15+
# 将海龟移动到指定的坐标
16+
17+
t.penup()
18+
t.goto(53.14, 113.29)
19+
t.pendown()
20+
21+
t.setheading(300)
22+
t.circle(-150, 30)
23+
t.setheading(295)
24+
t.circle(-140, 20)
25+
print(t.position())
26+
t.forward(5)
27+
t.setheading(260)
28+
t.circle(-80, 70)
29+
print(t.position())
30+
t.penup()
31+
t.goto(-74.43, -79.09)
32+
t.pendown()
33+
34+
t.penup()
35+
# 将海龟移动到指定的坐标
36+
t.goto(-144, 103)
37+
t.pendown()
38+
t.setheading(242)
39+
t.circle(110, 35)
40+
t.right(10)
41+
t.forward(10)
42+
t.setheading(250)
43+
t.circle(80, 115)
44+
print(t.position())
45+
46+
t.penup()
47+
t.goto(-74.43, -79.09)
48+
t.pendown()
49+
t.setheading(10)
50+
t.penup()
51+
t.goto(-144, 103)
52+
53+
t.pendown()
54+
t.penup()
55+
t.goto(x, y)
56+
t.pendown()
57+
58+
t.end_fill()
59+
60+
# 下巴
61+
t.penup()
62+
t.goto(-50, -82.09)
63+
t.pendown()
64+
t.pencolor("#DDA120")
65+
t.fillcolor("#DDA120")
66+
t.begin_fill()
67+
t.setheading(-12)
68+
t.circle(120, 25)
69+
t.setheading(-145)
70+
t.forward(30)
71+
t.setheading(180)
72+
t.circle(-20, 20)
73+
t.setheading(143)
74+
t.forward(30)
75+
t.end_fill()
76+
# penup()
77+
# # 将海龟移动到指定的坐标
78+
# goto(0, 0)
79+
# pendown()
80+
81+
82+
def eye():
83+
"""画眼睛"""
84+
# 左眼
85+
t.color("black", "black")
86+
t.penup()
87+
t.goto(-110, 27)
88+
t.pendown()
89+
t.begin_fill()
90+
t.setheading(0)
91+
t.circle(24)
92+
t.end_fill()
93+
# 左眼仁
94+
t.color("white", "white")
95+
t.penup()
96+
t.goto(-105, 51)
97+
t.pendown()
98+
t.begin_fill()
99+
t.setheading(0)
100+
t.circle(10)
101+
t.end_fill()
102+
# 右眼
103+
t.color("black", "black")
104+
t.penup()
105+
t.goto(25, 40)
106+
t.pendown()
107+
t.begin_fill()
108+
t.setheading(0)
109+
t.circle(24)
110+
t.end_fill()
111+
# 右眼仁
112+
t.color("white", "white")
113+
t.penup()
114+
t.goto(17, 62)
115+
t.pendown()
116+
t.begin_fill()
117+
t.setheading(0)
118+
t.circle(10)
119+
t.end_fill()
120+
121+
122+
def cheek():
123+
"""画脸颊"""
124+
# 右边
125+
t.color("#9E4406", "#FE2C21")
126+
t.penup()
127+
t.goto(-130, -50)
128+
t.pendown()
129+
t.begin_fill()
130+
t.setheading(0)
131+
t.circle(27)
132+
t.end_fill()
133+
134+
# 左边
135+
t.color("#9E4406", "#FE2C21")
136+
t.penup()
137+
t.goto(53, -20)
138+
t.pendown()
139+
t.begin_fill()
140+
t.setheading(0)
141+
t.circle(27)
142+
t.end_fill()
143+
144+
145+
def nose():
146+
"""画鼻子"""
147+
t.color("black", "black")
148+
t.penup()
149+
t.goto(-40, 38)
150+
t.pendown()
151+
t.begin_fill()
152+
t.circle(7, steps=3)
153+
t.end_fill()
154+
155+
156+
def mouth():
157+
"""画嘴"""
158+
t.color("black", "#F35590")
159+
# 嘴唇
160+
t.penup()
161+
t.goto(-10, 22)
162+
t.pendown()
163+
t.begin_fill()
164+
t.setheading(260)
165+
t.forward(60)
166+
t.circle(-11, 150)
167+
t.forward(55)
168+
print(t.position())
169+
t.penup()
170+
t.goto(-38.46, 21.97)
171+
t.pendown()
172+
t.end_fill()
173+
174+
# 舌头
175+
t.color("#6A070D", "#6A070D")
176+
t.begin_fill()
177+
t.penup()
178+
t.goto(-10.00, 22.00)
179+
t.pendown()
180+
t.penup()
181+
t.goto(-14.29, -1.7)
182+
t.pendown()
183+
t.penup()
184+
t.goto(-52, -5)
185+
t.pendown()
186+
t.penup()
187+
t.goto(-60.40, 12.74)
188+
t.pendown()
189+
t.penup()
190+
t.goto(-38.46, 21.97)
191+
t.pendown()
192+
t.penup()
193+
t.goto(-10.00, 22.00)
194+
t.pendown()
195+
196+
t.end_fill()
197+
198+
t.color("black", "#FFD624")
199+
200+
t.penup()
201+
t.goto(-78, 15)
202+
t.pendown()
203+
t.begin_fill()
204+
t.setheading(-25)
205+
for i in range(2):
206+
t.setheading(-25)
207+
t.circle(35, 70)
208+
209+
t.end_fill()
210+
t.color("#AB1945", "#AB1945")
211+
t.penup()
212+
t.goto(-52, -5)
213+
t.pendown()
214+
t.begin_fill()
215+
t.setheading(40)
216+
t.circle(-33, 70)
217+
t.goto(-16, -1.7)
218+
t.penup()
219+
t.goto(-18, -17)
220+
t.pendown()
221+
t.setheading(155)
222+
t.circle(25, 70)
223+
t.end_fill()
224+
225+
226+
def ear():
227+
"""画耳朵"""
228+
# 左耳
229+
t.color("black", "#FFD624")
230+
t.penup()
231+
t.goto(-145, 93)
232+
t.pendown()
233+
t.begin_fill()
234+
t.setheading(165)
235+
t.circle(-248, 50)
236+
t.right(120)
237+
t.circle(-248, 50)
238+
t.end_fill()
239+
t.color("black", "black")
240+
t.penup()
241+
t.goto(-240, 143)
242+
t.pendown()
243+
t.begin_fill()
244+
t.setheading(107)
245+
t.circle(-170, 25)
246+
t.left(80)
247+
t.circle(229, 15)
248+
t.left(120)
249+
t.circle(300, 15)
250+
t.end_fill()
251+
252+
# 右耳
253+
t.color("black", "#FFD624")
254+
t.penup()
255+
t.goto(30, 136)
256+
t.pendown()
257+
t.begin_fill()
258+
t.setheading(64)
259+
t.circle(-248, 50)
260+
261+
t.right(120)
262+
t.circle(-248, 50)
263+
t.end_fill()
264+
t.color("black", "black")
265+
t.penup()
266+
t.goto(160, 200)
267+
t.pendown()
268+
t.begin_fill()
269+
t.setheading(52)
270+
t.circle(170, 25)
271+
t.left(116)
272+
t.circle(229, 15)
273+
t.left(71)
274+
t.circle(-300, 15)
275+
t.end_fill()
276+
277+
def setting():
278+
"""设置参数"""
279+
t.pensize(2)
280+
# 隐藏海龟
281+
t.hideturtle()
282+
t.speed(10)
283+
284+
285+
def main():
286+
"""主函数"""
287+
setting()
288+
face(-132, 115)
289+
eye()
290+
cheek()
291+
nose()
292+
mouth()
293+
ear()
294+
t.done()
295+
296+
297+
if __name__ == '__main__':
298+
main()

0 commit comments

Comments
 (0)