当前位置:   article > 正文

用Python的Turtle画哆啦A梦_哆啦a梦代码编程python

哆啦a梦代码编程python

这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家。

这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考。

若有兴趣可以自行优化简洁代码,有时间我也会重新写一遍。

画出来的效果如下图:

代码如下:

  1. # * -- utf-8 -- *
  2. # Author: Tang
  3. import turtle as t
  4. t.speed(10)
  5. t.pensize(8)
  6. t.hideturtle()
  7. t.screensize(500, 500, bg='white')
  8. # 猫脸
  9. t.fillcolor('#00A1E8')
  10. t.begin_fill()
  11. t.circle(120)
  12. t.end_fill()
  13. t.pensize(3)
  14. t.fillcolor('white')
  15. t.begin_fill()
  16. t.circle(100)
  17. t.end_fill()
  18. t.pu()
  19. t.home()
  20. t.goto(0, 134)
  21. t.pd()
  22. t.pensize(4)
  23. t.fillcolor("#EA0014")
  24. t.begin_fill()
  25. t.circle(18)
  26. t.end_fill()
  27. t.pu()
  28. t.goto(7, 155)
  29. t.pensize(2)
  30. t.color('white', 'white')
  31. t.pd()
  32. t.begin_fill()
  33. t.circle(4)
  34. t.end_fill()
  35. t.pu()
  36. t.goto(-30, 160)
  37. t.pensize(4)
  38. t.pd()
  39. t.color('black', 'white')
  40. t.begin_fill()
  41. a = 0.4
  42. for i in range(120):
  43. if 0 <= i < 30 or 60 <= i < 90:
  44. a = a+0.08
  45. t.lt(3) #向左转3度
  46. t.fd(a) #向前走a的步长
  47. else:
  48. a = a-0.08
  49. t.lt(3)
  50. t.fd(a)
  51. t.end_fill()
  52. t.pu()
  53. t.goto(30, 160)
  54. t.pensize(4)
  55. t.pd()
  56. t.color('black', 'white')
  57. t.begin_fill()
  58. for i in range(120):
  59. if 0 <= i < 30 or 60 <= i < 90:
  60. a = a+0.08
  61. t.lt(3) # 向左转3度
  62. t.fd(a) # 向前走a的步长
  63. else:
  64. a = a-0.08
  65. t.lt(3)
  66. t.fd(a)
  67. t.end_fill()
  68. t.pu()
  69. t.goto(-38,190)
  70. t.pensize(8)
  71. t.pd()
  72. t.right(-30)
  73. t.forward(15)
  74. t.right(70)
  75. t.forward(15)
  76. t.pu()
  77. t.goto(15, 185)
  78. t.pensize(4)
  79. t.pd()
  80. t.color('black', 'black')
  81. t.begin_fill()
  82. t.circle(13)
  83. t.end_fill()
  84. t.pu()
  85. t.goto(13, 190)
  86. t.pensize(2)
  87. t.pd()
  88. t.color('white', 'white')
  89. t.begin_fill()
  90. t.circle(5)
  91. t.end_fill()
  92. t.pu()
  93. t.home()
  94. t.goto(0, 134)
  95. t.pensize(4)
  96. t.pencolor('black')
  97. t.pd()
  98. t.right(90)
  99. t.forward(40)
  100. t.pu()
  101. t.home()
  102. t.goto(0, 124)
  103. t.pensize(3)
  104. t.pencolor('black')
  105. t.pd()
  106. t.left(10)
  107. t.forward(80)
  108. t.pu()
  109. t.home()
  110. t.goto(0, 114)
  111. t.pensize(3)
  112. t.pencolor('black')
  113. t.pd()
  114. t.left(6)
  115. t.forward(80)
  116. t.pu()
  117. t.home()
  118. t.goto(0,104)
  119. t.pensize(3)
  120. t.pencolor('black')
  121. t.pd()
  122. t.left(0)
  123. t.forward(80)
  124. # 左边的胡子
  125. t.pu()
  126. t.home()
  127. t.goto(0,124)
  128. t.pensize(3)
  129. t.pencolor('black')
  130. t.pd()
  131. t.left(170)
  132. t.forward(80)
  133. t.pu()
  134. t.home()
  135. t.goto(0, 114)
  136. t.pensize(3)
  137. t.pencolor('black')
  138. t.pd()
  139. t.left(174)
  140. t.forward(80)
  141. t.pu()
  142. t.home()
  143. t.goto(0, 104)
  144. t.pensize(3)
  145. t.pencolor('black')
  146. t.pd()
  147. t.left(180)
  148. t.forward(80)
  149. t.pu()
  150. t.goto(-70, 70)
  151. t.pd()
  152. t.color('black', 'red')
  153. t.pensize(6)
  154. t.seth(-60)
  155. t.begin_fill()
  156. t.circle(80,40)
  157. t.circle(80,80)
  158. t.end_fill()
  159. t.pu()
  160. t.home()
  161. t.goto(-80,70)
  162. t.pd()
  163. t.forward(160)
  164. t.pu()
  165. t.home()
  166. t.goto(-50,50)
  167. t.pd()
  168. t.pensize(1)
  169. t.fillcolor("#eb6e1a")
  170. t.seth(40)
  171. t.begin_fill()
  172. t.circle(-40, 40)
  173. t.circle(-40, 40)
  174. t.seth(40)
  175. t.circle(-40, 40)
  176. t.circle(-40, 40)
  177. t.seth(220)
  178. t.circle(-80, 40)
  179. t.circle(-80, 40)
  180. t.end_fill()
  181. # 领带
  182. t.pu()
  183. t.goto(-70, 12)
  184. t.pensize(14)
  185. t.pencolor('red')
  186. t.pd()
  187. t.seth(-20)
  188. t.circle(200, 30)
  189. t.circle(200, 10)
  190. # 铃铛
  191. t.pu()
  192. t.goto(0, -46)
  193. t.pd()
  194. t.pensize(3)
  195. t.color("black", '#f8d102')
  196. t.begin_fill()
  197. t.circle(25)
  198. t.end_fill()
  199. t.pu()
  200. t.goto(-5, -40)
  201. t.pd()
  202. t.pensize(2)
  203. t.color("black", '#79675d')
  204. t.begin_fill()
  205. t.circle(5)
  206. t.end_fill()
  207. t.pensize(3)
  208. t.right(115)
  209. t.forward(7)
  210. t.mainloop()

转载请注明出处

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

闽ICP备14008679号