Python实例练手项目源码 - 小猪佩奇

举报
CodeAllen 发表于 2021/10/29 23:57:24 2021/10/29
【摘要】 游戏效果 源码 # coding: utf-8 import turtle as t t.screensize(400, 300)t.pensize(4) # 设置画笔的大小t.colormode(255) # 设置GBK颜色范围为0-255t.color((255, 155, 192), "pink") # 设置画笔颜色...

游戏效果

源码


  
  1. # coding: utf-8
  2. import turtle as t
  3. t.screensize(400, 300)
  4. t.pensize(4) # 设置画笔的大小
  5. t.colormode(255) # 设置GBK颜色范围为0-255
  6. t.color((255, 155, 192), "pink") # 设置画笔颜色和填充颜色(pink)
  7. t.setup(840, 500) # 设置主窗口的大小为840*500
  8. t.speed(10) # 设置画笔速度为10
  9. # 鼻子
  10. t.pu() # 提笔
  11. t.goto(-100, 100) # 画笔前往坐标(-100,100)
  12. t.pd() # 下笔
  13. t.seth(-30) # 笔的角度为-30°
  14. t.begin_fill() # 外形填充的开始标志
  15. a = 0.4
  16. for i in range(120):
  17. if 0 <= i < 30 or 60 <= i < 90:
  18. a = a + 0.08
  19. t.lt(3) # 向左转3度
  20. t.fd(a) # 向前走a的步长
  21. else:
  22. a = a - 0.08
  23. t.lt(3)
  24. t.fd(a)
  25. t.end_fill() # 依据轮廓填充
  26. t.pu() # 提笔
  27. t.seth(90) # 笔的角度为90度
  28. t.fd(25) # 向前移动25
  29. t.seth(0) # 转换画笔的角度为0
  30. t.fd(10)
  31. t.pd()
  32. t.pencolor(255, 155, 192) # 设置画笔颜色
  33. t.seth(10)
  34. t.begin_fill()
  35. t.circle(5) # 画一个半径为5的圆
  36. t.color(160, 82, 45) # 设置画笔和填充颜色
  37. t.end_fill()
  38. t.pu()
  39. t.seth(0)
  40. t.fd(20)
  41. t.pd()
  42. t.pencolor(255, 155, 192)
  43. t.seth(10)
  44. t.begin_fill()
  45. t.circle(5)
  46. t.color(160, 82, 45)
  47. t.end_fill()
  48. # 头
  49. t.color((255, 155, 192), "pink")
  50. t.pu()
  51. t.seth(90)
  52. t.fd(41)
  53. t.seth(0)
  54. t.fd(0)
  55. t.pd()
  56. t.begin_fill()
  57. t.seth(180)
  58. t.circle(300, -30) # 顺时针画一个半径为300,圆心角为30°的园
  59. t.circle(100, -60)
  60. t.circle(80, -100)
  61. t.circle(150, -20)
  62. t.circle(60, -95)
  63. t.seth(161)
  64. t.circle(-300, 15)
  65. t.pu()
  66. t.goto(-100, 100)
  67. t.pd()
  68. t.seth(-30)
  69. a = 0.4
  70. for i in range(60):
  71. if 0 <= i < 30 or 60 <= i < 90:
  72. a = a + 0.08
  73. t.lt(3) # 向左转3度
  74. t.fd(a) # 向前走a的步长
  75. else:
  76. a = a - 0.08
  77. t.lt(3)
  78. t.fd(a)
  79. t.end_fill()
  80. # 耳朵
  81. t.color((255, 155, 192), "pink")
  82. t.pu()
  83. t.seth(90)
  84. t.fd(-7)
  85. t.seth(0)
  86. t.fd(70)
  87. t.pd()
  88. t.begin_fill()
  89. t.seth(100)
  90. t.circle(-50, 50)
  91. t.circle(-10, 120)
  92. t.circle(-50, 54)
  93. t.end_fill()
  94. t.pu()
  95. t.seth(90)
  96. t.fd(-12)
  97. t.seth(0)
  98. t.fd(30)
  99. t.pd()
  100. t.begin_fill()
  101. t.seth(100)
  102. t.circle(-50, 50)
  103. t.circle(-10, 120)
  104. t.circle(-50, 56)
  105. t.end_fill()
  106. # 眼睛
  107. t.color((255, 155, 192), "white")
  108. t.pu()
  109. t.seth(90)
  110. t.fd(-20)
  111. t.seth(0)
  112. t.fd(-95)
  113. t.pd()
  114. t.begin_fill()
  115. t.circle(15)
  116. t.end_fill()
  117. t.color("black")
  118. t.pu()
  119. t.seth(90)
  120. t.fd(12)
  121. t.seth(0)
  122. t.fd(-3)
  123. t.pd()
  124. t.begin_fill()
  125. t.circle(3)
  126. t.end_fill()
  127. t.color((255, 155, 192), "white")
  128. t.pu()
  129. t.seth(90)
  130. t.fd(-25)
  131. t.seth(0)
  132. t.fd(40)
  133. t.pd()
  134. t.begin_fill()
  135. t.circle(15)
  136. t.end_fill()
  137. t.color("black")
  138. t.pu()
  139. t.seth(90)
  140. t.fd(12)
  141. t.seth(0)
  142. t.fd(-3)
  143. t.pd()
  144. t.begin_fill()
  145. t.circle(3)
  146. t.end_fill()
  147. # 腮
  148. t.color((255, 155, 192))
  149. t.pu()
  150. t.seth(90)
  151. t.fd(-95)
  152. t.seth(0)
  153. t.fd(65)
  154. t.pd()
  155. t.begin_fill()
  156. t.circle(30)
  157. t.end_fill()
  158. # 嘴
  159. t.color(239, 69, 19)
  160. t.pu()
  161. t.seth(90)
  162. t.fd(15)
  163. t.seth(0)
  164. t.fd(-100)
  165. t.pd()
  166. t.seth(-80)
  167. t.circle(30, 40)
  168. t.circle(40, 80)
  169. # 身体
  170. t.color("red", (255, 99, 71))
  171. t.pu()
  172. t.seth(90)
  173. t.fd(-20)
  174. t.seth(0)
  175. t.fd(-78)
  176. t.pd()
  177. t.begin_fill()
  178. t.seth(-130)
  179. t.circle(100, 10)
  180. t.circle(300, 30)
  181. t.seth(0)
  182. t.fd(230)
  183. t.seth(90)
  184. t.circle(300, 30)
  185. t.circle(100, 3)
  186. t.color((255, 155, 192), (255, 100, 100))
  187. t.seth(-135)
  188. t.circle(-80, 63)
  189. t.circle(-150, 24)
  190. t.end_fill()
  191. # 手
  192. t.color((255, 155, 192))
  193. t.pu()
  194. t.seth(90)
  195. t.fd(-40)
  196. t.seth(0)
  197. t.fd(-27)
  198. t.pd()
  199. t.seth(-160)
  200. t.circle(300, 15)
  201. t.pu()
  202. t.seth(90)
  203. t.fd(15)
  204. t.seth(0)
  205. t.fd(0)
  206. t.pd()
  207. t.seth(-10)
  208. t.circle(-20, 90)
  209. t.pu()
  210. t.seth(90)
  211. t.fd(30)
  212. t.seth(0)
  213. t.fd(237)
  214. t.pd()
  215. t.seth(-20)
  216. t.circle(-300, 15)
  217. t.pu()
  218. t.seth(90)
  219. t.fd(20)
  220. t.seth(0)
  221. t.fd(0)
  222. t.pd()
  223. t.seth(-170)
  224. t.circle(20, 90)
  225. # 脚
  226. t.pensize(10)
  227. t.color((240, 128, 128))
  228. t.pu()
  229. t.seth(90)
  230. t.fd(-75)
  231. t.seth(0)
  232. t.fd(-180)
  233. t.pd()
  234. t.seth(-90)
  235. t.fd(40)
  236. t.seth(-180)
  237. t.color("black")
  238. t.pensize(15)
  239. t.fd(20)
  240. t.pensize(10)
  241. t.color((240, 128, 128))
  242. t.pu()
  243. t.seth(90)
  244. t.fd(40)
  245. t.seth(0)
  246. t.fd(90)
  247. t.pd()
  248. t.seth(-90)
  249. t.fd(40)
  250. t.seth(-180)
  251. t.color("black")
  252. t.pensize(15)
  253. t.fd(20)
  254. # 尾巴
  255. t.pensize(4)
  256. t.color((255, 155, 192))
  257. t.pu()
  258. t.seth(90)
  259. t.fd(70)
  260. t.seth(0)
  261. t.fd(95)
  262. t.pd()
  263. t.seth(0)
  264. t.circle(70, 20)
  265. t.circle(10, 330)
  266. t.circle(70, 30)
  267. t.done()

 

文章来源: allen5g.blog.csdn.net,作者:CodeAllen的博客,版权归原作者所有,如需转载,请联系作者。

原文链接:allen5g.blog.csdn.net/article/details/117637861

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。