python绘制小猪佩奇

1.打开idle

2.点击File-New Files

3.输入以下代码

1.   from turtle import *
2.
3. def nose(x,y):#鼻子
4. penup()#提起笔
5. goto(x,y)#定位
6. pendown()#落笔,开始画
7. setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
8. begin_fill()#准备开始填充图形
9. a=0.4
10. for i in range(120):
11. if 0<=i<30 or 60<=i<90:
12. a=a+0.08
13. left(3) #向左转3度
14. forward(a) #向前走a的步长
15. else:
16. a=a-0.08
17. left(3)
18. forward(a)
19. end_fill()#填充完成
20.
21. penup()
22. setheading(90)
23. forward(25)
24. setheading(0)
25. forward(10)
26. pendown()
27. pencolor(255,155,192)#画笔颜色
28. setheading(10)
29. begin_fill()
30. circle(5)
31. color(160,82,45)#返回或设置pencolor和fillcolor
32. end_fill()
33.
34. penup()
35. setheading(0)
36. forward(20)
37. pendown()
38. pencolor(255,155,192)
39. setheading(10)
40. begin_fill()
41. circle(5)
42. color(160,82,45)
43. end_fill()
44.
45.
46. def head(x,y):#头
47. color((255,155,192),"pink")
48. penup()
49. goto(x,y)
50. setheading(0)
51. pendown()
52. begin_fill()
53. setheading(180)
54. circle(300,-30)
55. circle(100,-60)
56. circle(80,-100)
57. circle(150,-20)
58. circle(60,-95)
59. setheading(161)
60. circle(-300,15)
61. penup()
62. goto(-100,100)
63. pendown()
64. setheading(-30)
65. a=0.4
66. for i in range(60):
67. if 0<=i<30 or 60<=i<90:
68. a=a+0.08
69. lt(3) #向左转3度
70. fd(a) #向前走a的步长
71. else:
72. a=a-0.08
73. lt(3)
74. fd(a)
75. end_fill()
76.
77.
78. def ears(x,y): #耳朵
79. color((255,155,192),"pink")
80. penup()
81. goto(x,y)
82. pendown()
83. begin_fill()
84. setheading(100)
85. circle(-50,50)
86. circle(-10,120)
87. circle(-50,54)
88. end_fill()
89.
90. penup()
91. setheading(90)
92. forward(-12)
93. setheading(0)
94. forward(30)
95. pendown()
96. begin_fill()
97. setheading(100)
98. circle(-50,50)
99. circle(-10,120)
100. circle(-50,56)
101. end_fill()
102.
103.
104. def eyes(x,y):#眼睛
105. color((255,155,192),"white")
106. penup()
107. setheading(90)
108. forward(-20)
109. setheading(0)
110. forward(-95)
111. pendown()
112. begin_fill()
113. circle(15)
114. end_fill()
115.
116. color("black")
117. penup()
118. setheading(90)
119. forward(12)
120. setheading(0)
121. forward(-3)
122. pendown()
123. begin_fill()
124. circle(3)
125. end_fill()
126.
127. color((255,155,192),"white")
128. penup()
129. seth(90)
130. forward(-25)
131. seth(0)
132. forward(40)
133. pendown()
134. begin_fill()
135. circle(15)
136. end_fill()
137.
138. color("black")
139. penup()
140. setheading(90)
141. forward(12)
142. setheading(0)
143. forward(-3)
144. pendown()
145. begin_fill()
146. circle(3)
147. end_fill()
148.
149.
150. def cheek(x,y):#腮
151. color((255,155,192))
152. penup()
153. goto(x,y)
154. pendown()
155. setheading(0)
156. begin_fill()
157. circle(30)
158. end_fill()
159.
160.
161. def mouth(x,y): #嘴
162. color(239,69,19)
163. penup()
164. goto(x,y)
165. pendown()
166. setheading(-80)
167. circle(30,40)
168. circle(40,80)
169.
170. def body(x,y):#身体
171. color("red",(255,99,71))
172. penup()
173. goto(x,y)
174. pendown()
175. begin_fill()
176. setheading(-130)
177. circle(100,10)
178. circle(300,30)
179. setheading(0)
180. forward(230)
181. setheading(90)
182. circle(300,30)
183. circle(100,3)
184. color((255,155,192),(255,100,100))
185. setheading(-135)
186. circle(-80,63)
187. circle(-150,24)
188. end_fill()
189.
190.
191. def hands(x,y):#手
192. color((255,155,192))
193. penup()
194. goto(x,y)
195. pendown()
196. setheading(-160)
197. circle(300,15)
198. penup()
199. setheading(90)
200. forward(15)
201. setheading(0)
202. forward(0)
203. pendown()
204. setheading(-10)
205. circle(-20,90)
206.
207. penup()
208. setheading(90)
209. forward(30)
210. setheading(0)
211. forward(237)
212. pendown()
213. setheading(-20)
214. circle(-300,15)
215. penup()
216. setheading(90)
217. forward(20)
218. setheading(0)
219. forward(0)
220. pendown()
221. setheading(-170)
222. circle(20,90)
223.
224. def foot(x,y):#脚
225. pensize(10)
226. color((240,128,128))
227. penup()
228. goto(x,y)
229. pendown()
230. setheading(-90)
231. forward(40)
232. setheading(-180)
233. color("black")
234. pensize(15)
235. fd(20)
236.
237. pensize(10)
238. color((240,128,128))
239. penup()
240. setheading(90)
241. forward(40)
242. setheading(0)
243. forward(90)
244. pendown()
245. setheading(-90)
246. forward(40)
247. setheading(-180)
248. color("black")
249. pensize(15)
250. fd(20)
251.
252. def tail(x,y):#尾巴
253. pensize(4)
254. color((255,155,192))
255. penup()
256. goto(x,y)
257. pendown()
258. seth(0)
259. circle(70,20)
260. circle(10,330)
261. circle(70,30)
262.
263. def setting(): #参数设置
264. pensize(4)
265. hideturtle() #使乌龟无形(隐藏)
266. colormode(255) #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内
267. color((255,155,192),"pink")
268. setup(840,500)
269. speed(10)
270.
271. def main():
272. setting() #画布、画笔设置
273. nose(-100,100) #鼻子
274. head(-69,167) #头
275. ears(0,160) #耳朵
276. eyes(0,140) #眼睛
277. cheek(80,10) #腮
278. mouth(-20,30) #嘴
279. body(-32,-8) #身体
280. hands(-56,-45) #手
281. foot(2,-177) #脚
282. tail(148,-155) #尾巴
283. done()
284.
285. if __name__ == '__main__':
286. main()

4.点击run 或者直接按F5

  过程I

     

过程II

 

运行完毕

运用python绘制小猪佩奇的更多相关文章

  1. python 画小猪佩奇

    转自:python画个小猪佩奇 # -*- coding: utf-8 -*- """ Created on Mon May 20 11:36:03 2019 @auth ...

  2. python3用turtle库进行绘制小猪佩奇图案

    晚上闲着无事,深入学习这个turtle用法,就做了小猪佩奇图 附上代码: # coding: utf-8 #功能:绘画小猪佩奇 import turtle as t t.screensize(400, ...

  3. 用python画小猪佩奇(非原创)

    略作改动: # coding:utf-8 import turtle as t t.screensize(400, 300, "blue") t.pensize(4) # 设置画笔 ...

  4. 利用python画小猪佩奇

    import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.color((255,155,192),"pink&quo ...

  5. python 画个小猪佩奇

    不知道大家小时候有没有学习过logo语言,就是操纵一只小王八,来画各种图案.博主小学微机课就学习了这个,最近发现python的turtle包就是logo语言,所以画个小猪佩奇和大家分享. 代码来自知乎 ...

  6. Python之turtle库-小猪佩奇

    Python之turtle库-小猪佩奇 #!/usr/bin/env python # coding: utf-8 # Python turtle库官方文档:https://docs.python.o ...

  7. *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

    如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...

  8. Python爬虫入门教程 45-100 Charles抓取兔儿故事-下载小猪佩奇故事-手机APP爬虫部分

    1. Charles抓取兔儿故事背景介绍 之前已经安装了Charles,接下来我将用两篇博客简单写一下关于Charles的使用,今天抓取一下兔儿故事里面关于小猪佩奇的故事. 爬虫编写起来核心的重点是分 ...

  9. 如何优雅的使用C语言绘制一只小猪佩奇

    今天我们来用C语言画一只小猪佩奇---社会.社会....在画小猪佩奇之前,我们先使用带符号的距离长 (signed distance field,SDF) 来画一个圆形. 使用这个方法表示形状,但是这 ...

随机推荐

  1. GO函数

    函数定义 Go语言中定义函数使用func关键字. func 函数名(参数)(返回值){ 函数体 } 函数名:由字母.数字.下划线组成.但函数名的第一个字母不能是数字.在同一个包内,函数名也称不能重名( ...

  2. ssm框架搭建的基本配置(一站式教会你搭建)

    首先是需要的jar包: <dependency> <groupId>org.springframework</groupId> <artifactId> ...

  3. 五一培训 DAY1

    DAY1 枚举 例题1 题解: 例题2 题解: 例题3 题解: vis[ ]判断是否为素数,pri[ ]储存素数 例题4 题解: 例题5 题解: PS: i  <  1<<n    ...

  4. TeamCity安装

    1 使用docker安装 安装手册:https://hub.docker.com/r/jetbrains/teamcity-server/2 安装包安装. docker run -it --name ...

  5. flutter-fluro

    路由传参 route.dart import 'package:fluro/fluro.dart'; //添加页面 import 'package:m/pages/loginPage.dart'; i ...

  6. [Python数据挖掘]第5章、挖掘建模(下)

    四.关联规则 Apriori算法代码(被调函数部分没怎么看懂) from __future__ import print_function import pandas as pd #自定义连接函数,用 ...

  7. opencv学习之路(29)、轮廓查找与绘制(八)——轮廓特征属性及应用

    一.简介 HSV颜色空间(hue色调,saturation饱和度,value亮度) 二.HSV滑动条 #include "opencv2/opencv.hpp" #include ...

  8. bzoj 4767 两双手 - 动态规划 - 容斥原理

    题目传送门 传送门I 传送门II 题目大意 一个无限大的棋盘上有一只马,设马在某个时刻的位置为$(x, y)$, 每次移动可以将马移动到$(x + A_x, y + A_y)$或者$(x + B_x, ...

  9. LINQ更新提示找不到行或行已更改的解决一例

    LINQ对一行数据进行更改,怎么都无法提交,所有字段值都不是空值,后来看了实体,我发现更改的数据是主键,去数据库看这个字段却不是主键,原来是数据库取消主键了,实体代码没取消,因为更改了主键,所以无法更 ...

  10. react-native webView android使用本地html问题

    react-native WebView组件使用本地html时候,一般都是这样使用 var source = require('../html/my.html') : <WebView sour ...