CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day01/peppa_pig.py
Views: 729
1
"""
2
绘制小猪佩奇
3
"""
4
from turtle import *
5
6
7
def nose(x,y):
8
"""画鼻子"""
9
penup()
10
# 将海龟移动到指定的坐标
11
goto(x,y)
12
pendown()
13
# 设置海龟的方向(0-东、90-北、180-西、270-南)
14
setheading(-30)
15
begin_fill()
16
a = 0.4
17
for i in range(120):
18
if 0 <= i < 30 or 60 <= i <90:
19
a = a + 0.08
20
# 向左转3度
21
left(3)
22
# 向前走
23
forward(a)
24
else:
25
a = a - 0.08
26
left(3)
27
forward(a)
28
end_fill()
29
penup()
30
setheading(90)
31
forward(25)
32
setheading(0)
33
forward(10)
34
pendown()
35
# 设置画笔的颜色(红, 绿, 蓝)
36
pencolor(255, 155, 192)
37
setheading(10)
38
begin_fill()
39
circle(5)
40
color(160, 82, 45)
41
end_fill()
42
penup()
43
setheading(0)
44
forward(20)
45
pendown()
46
pencolor(255, 155, 192)
47
setheading(10)
48
begin_fill()
49
circle(5)
50
color(160, 82, 45)
51
end_fill()
52
53
54
def head(x, y):
55
"""画头"""
56
color((255, 155, 192), "pink")
57
penup()
58
goto(x,y)
59
setheading(0)
60
pendown()
61
begin_fill()
62
setheading(180)
63
circle(300, -30)
64
circle(100, -60)
65
circle(80, -100)
66
circle(150, -20)
67
circle(60, -95)
68
setheading(161)
69
circle(-300, 15)
70
penup()
71
goto(-100, 100)
72
pendown()
73
setheading(-30)
74
a = 0.4
75
for i in range(60):
76
if 0<= i < 30 or 60 <= i < 90:
77
a = a + 0.08
78
lt(3) #向左转3度
79
fd(a) #向前走a的步长
80
else:
81
a = a - 0.08
82
lt(3)
83
fd(a)
84
end_fill()
85
86
87
def ears(x,y):
88
"""画耳朵"""
89
color((255, 155, 192), "pink")
90
penup()
91
goto(x, y)
92
pendown()
93
begin_fill()
94
setheading(100)
95
circle(-50, 50)
96
circle(-10, 120)
97
circle(-50, 54)
98
end_fill()
99
penup()
100
setheading(90)
101
forward(-12)
102
setheading(0)
103
forward(30)
104
pendown()
105
begin_fill()
106
setheading(100)
107
circle(-50, 50)
108
circle(-10, 120)
109
circle(-50, 56)
110
end_fill()
111
112
113
def eyes(x,y):
114
"""画眼睛"""
115
color((255, 155, 192), "white")
116
penup()
117
setheading(90)
118
forward(-20)
119
setheading(0)
120
forward(-95)
121
pendown()
122
begin_fill()
123
circle(15)
124
end_fill()
125
color("black")
126
penup()
127
setheading(90)
128
forward(12)
129
setheading(0)
130
forward(-3)
131
pendown()
132
begin_fill()
133
circle(3)
134
end_fill()
135
color((255, 155, 192), "white")
136
penup()
137
seth(90)
138
forward(-25)
139
seth(0)
140
forward(40)
141
pendown()
142
begin_fill()
143
circle(15)
144
end_fill()
145
color("black")
146
penup()
147
setheading(90)
148
forward(12)
149
setheading(0)
150
forward(-3)
151
pendown()
152
begin_fill()
153
circle(3)
154
end_fill()
155
156
157
def cheek(x,y):
158
"""画脸颊"""
159
color((255, 155, 192))
160
penup()
161
goto(x,y)
162
pendown()
163
setheading(0)
164
begin_fill()
165
circle(30)
166
end_fill()
167
168
169
def mouth(x,y):
170
"""画嘴巴"""
171
color(239, 69, 19)
172
penup()
173
goto(x, y)
174
pendown()
175
setheading(-80)
176
circle(30, 40)
177
circle(40, 80)
178
179
180
def setting():
181
"""设置参数"""
182
pensize(4)
183
# 隐藏海龟
184
hideturtle()
185
colormode(255)
186
color((255, 155, 192), "pink")
187
setup(840, 500)
188
speed(10)
189
190
191
def main():
192
"""主函数"""
193
setting()
194
nose(-100, 100)
195
head(-69, 167)
196
ears(0, 160)
197
eyes(0, 140)
198
cheek(80, 10)
199
mouth(-20, 30)
200
done()
201
202
203
if __name__ == '__main__':
204
main()
205
206