当前位置:   article > 正文

有趣的python代码系列四:小猪佩奇_xiaozhupeiqi python daima

xiaozhupeiqi python daima

先看效果图:

python代码: 

  1. import turtle
  2. from turtle import *
  3. turtle.title('小猪佩奇')
  4. def nose(x,y):
  5. """画鼻子"""
  6. pensize(5)
  7. pencolor((255, 155, 192))
  8. penup()
  9. # 将海龟移动到指定的坐标
  10. goto(x,y)
  11. pendown()
  12. # 设置海龟的方向(0-东、90-北、180-西、270-南)
  13. setheading(-30)
  14. begin_fill()
  15. fillcolor(255, 192, 203)
  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. def head(x, y):
  53. """画头"""
  54. color((255, 155, 192), "pink")
  55. penup()
  56. goto(x,y)
  57. setheading(0)
  58. pendown()
  59. begin_fill()
  60. setheading(180)
  61. circle(300, -30)
  62. circle(100, -60)
  63. circle(80, -100)
  64. circle(150, -20)
  65. circle(60, -95)
  66. setheading(161)
  67. circle(-300, 15)
  68. penup()
  69. goto(-100, 100)
  70. pendown()
  71. setheading(-30)
  72. a = 0.4
  73. for i in range(60):
  74. if 0<= i < 30 or 60 <= i < 90:
  75. a = a + 0.08
  76. lt(3) #向左转3度
  77. fd(a) #向前走a的步长
  78. else:
  79. a = a - 0.08
  80. lt(3)
  81. fd(a)
  82. end_fill()
  83. def ears(x,y):
  84. """画耳朵"""
  85. color((255, 155, 192), "pink")
  86. penup()
  87. goto(x, y)
  88. pendown()
  89. begin_fill()
  90. setheading(100)
  91. circle(-50, 50)
  92. circle(-10, 120)
  93. circle(-50, 54)
  94. end_fill()
  95. penup()
  96. setheading(90)
  97. forward(-12)
  98. setheading(0)
  99. forward(30)
  100. pendown()
  101. begin_fill()
  102. setheading(90)
  103. circle(-50, 50)
  104. circle(-10, 120)
  105. circle(-50, 56)
  106. end_fill()
  107. def eyes(x,y):
  108. """画眼睛"""
  109. color((255, 155, 192), "white")
  110. penup()
  111. setheading(90)
  112. forward(-20)
  113. setheading(0)
  114. forward(-95)
  115. pendown()
  116. begin_fill()
  117. circle(15)
  118. end_fill()
  119. color("black")
  120. penup()
  121. setheading(90)
  122. forward(12)
  123. setheading(0)
  124. forward(-3)
  125. pendown()
  126. begin_fill()
  127. circle(3)
  128. end_fill()
  129. color((255, 155, 192), "white")
  130. penup()
  131. seth(90)
  132. forward(-25)
  133. seth(0)
  134. forward(40)
  135. pendown()
  136. begin_fill()
  137. circle(15)
  138. end_fill()
  139. color("black")
  140. penup()
  141. setheading(90)
  142. forward(12)
  143. setheading(0)
  144. forward(-3)
  145. pendown()
  146. begin_fill()
  147. circle(3)
  148. end_fill()
  149. def cheek(x,y):
  150. """画脸颊"""
  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. def mouth(x,y):
  160. """画嘴巴"""
  161. color(239, 69, 19)
  162. penup()
  163. goto(x, y)
  164. pendown()
  165. setheading(-80)
  166. circle(30, 40)
  167. circle(40, 80)
  168. def body(x,y):
  169. '''画身体'''
  170. penup()
  171. goto(x,y)
  172. pencolor('red')
  173. fillcolor(250,106,106)
  174. pendown()
  175. begin_fill()
  176. setheading(-66)
  177. circle(-450,17)
  178. setheading(180)
  179. forward(185)
  180. setheading(85)
  181. circle(-450,17)
  182. end_fill()
  183. '''右手'''
  184. penup()
  185. goto(110,-45)
  186. pendown()
  187. pensize(8)
  188. pencolor(255, 192, 203)
  189. setheading(30)
  190. circle(-400,10)
  191. penup()
  192. goto(167,-5)
  193. pendown()
  194. setheading(-120)
  195. forward(20)
  196. left(100)
  197. forward(20)
  198. '''左手'''
  199. penup()
  200. goto(-25,-45)
  201. pendown()
  202. pencolor(255, 192, 203)
  203. setheading(150)
  204. circle(400,10)
  205. penup()
  206. goto(-78,-6)
  207. pendown()
  208. setheading(-60)
  209. forward(20)
  210. right(100)
  211. forward(20)
  212. def feet1(x,y):
  213. pensize(7)
  214. pencolor(255, 192, 203)
  215. penup()
  216. goto(x,y)
  217. setheading(-90)
  218. pendown()
  219. forward(10)
  220. penup()
  221. goto(x-12,y-10)
  222. pendown()
  223. pencolor(238,201,0)
  224. fillcolor(238,230,132)
  225. begin_fill()
  226. setheading(0)
  227. forward(24)
  228. right(90)
  229. forward(36)
  230. right(90)
  231. forward(40)
  232. circle(-10,180)
  233. forward(16)
  234. left(90)
  235. forward(12)
  236. end_fill()
  237. def feet2(x,y):
  238. pensize(7)
  239. pencolor(255, 192, 203)
  240. penup()
  241. goto(x,y)
  242. setheading(-90)
  243. pendown()
  244. forward(10)
  245. penup()
  246. goto(x-12,y-10)
  247. pendown()
  248. pencolor(238,201,0)
  249. fillcolor(238,230,132)
  250. begin_fill()
  251. setheading(0)
  252. forward(24)
  253. right(90)
  254. forward(36)
  255. right(90)
  256. forward(40)
  257. circle(-10,180)
  258. forward(16)
  259. left(90)
  260. forward(12)
  261. end_fill()
  262. def tail(x,y):
  263. pensize(8)
  264. penup()
  265. goto(x,y)
  266. pendown()
  267. pencolor(255, 192, 203)
  268. setheading(-5)
  269. circle(30,100)
  270. circle(10,180)
  271. circle(20,150)
  272. def backg(x):
  273. penup()
  274. goto(-420,x)
  275. setheading(0)
  276. fillcolor(50,205,50)
  277. begin_fill()
  278. forward(840)
  279. right(90)
  280. forward(300)
  281. right(90)
  282. forward(840)
  283. right(90)
  284. forward(300)
  285. end_fill()
  286. setheading(0)
  287. fillcolor(0,191,255)
  288. begin_fill()
  289. forward(840)
  290. left(90)
  291. forward(600)
  292. left(90)
  293. forward(840)
  294. left(90)
  295. forward(600)
  296. end_fill()
  297. def cloude1(x, y):
  298. """画云"""
  299. penup()
  300. goto(x,y)
  301. setheading(90)
  302. fillcolor(255,255,255)
  303. begin_fill()
  304. a = 0.4
  305. for i in range(120):
  306. if 0 <= i < 30 or 60 <= i <90:
  307. a = a + 0.14
  308. # 向左转3度
  309. left(3)
  310. # 向前走
  311. forward(a)
  312. else:
  313. a = a - 0.15
  314. left(3)
  315. forward(a)
  316. end_fill()
  317. def cloude2(x, y):
  318. """画云"""
  319. penup()
  320. goto(x,y)
  321. setheading(90)
  322. fillcolor(255,255,255)
  323. begin_fill()
  324. a = 0.4
  325. for i in range(120):
  326. if 0 <= i < 30 or 60 <= i <90:
  327. a = a + 0.15
  328. # 向左转3度
  329. left(3)
  330. # 向前走
  331. forward(a)
  332. else:
  333. a = a - 0.13
  334. left(3)
  335. forward(a)
  336. end_fill()
  337. def setting():
  338. """设置参数"""
  339. pensize(5)
  340. # 隐藏海龟
  341. hideturtle()
  342. colormode(255)
  343. color((255, 155, 192), "pink")
  344. setup(840, 700)
  345. speed(10)
  346. def main():
  347. """主函数"""
  348. setting()
  349. backg(0)
  350. body(105,-20)
  351. nose(-100, 100)
  352. head(-69, 167)
  353. ears(0, 160)
  354. eyes(0, 140)
  355. cheek(80, 10)
  356. mouth(-20, 30)
  357. feet1(10,-150)
  358. feet2(90,-150)
  359. tail(130,-110)
  360. cloude1(-200,200)
  361. cloude2(300,300)
  362. done()
  363. if __name__ == '__main__':
  364. main()

系列文章: 

有趣的python代码系列三:超萌的皮卡丘_wwwarewow的博客-CSDN博客
有趣的python代码系列二:温柔的狮子_wwwarewow的博客-CSDN博客
有趣的python系列一:代码实现酷炫的彩虹_wwwarewow的博客-CSDN博客

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/198665
推荐阅读
相关标签
  

闽ICP备14008679号