當前位置:
首頁 > 知識 > 用python實現小豬佩奇

用python實現小豬佩奇

[python] view plain copy

  1. import

    turtle as t
  2. t.pensize(4)
  3. t.hideturtle()
  4. t.colormode(255)
  5. t.color((255,155,192),"pink")
  6. t.setup(840,500)
  7. t.speed(10)
  8. #鼻子
  9. t.pu()
  10. t.goto(-100,100)
  11. t.pd()
  12. t.seth(-30)
  13. t.begin_fill()
  14. a=0.4
  15. for

    i

    in

    range(120):
  16. if

    0<=i<30

    or

    60<=i<90:
  17. a=a+0.08
  18. t.lt(3) #向左轉3度
  19. t.fd(a) #向前走a的步長
  20. else

    :

  21. a=a-0.08
  22. t.lt(3)
  23. t.fd(a)
  24. t.end_fill()
  25. t.pu()
  26. t.seth(90)
  27. t.fd(25)
  28. t.seth(0)
  29. t.fd(10)
  30. t.pd()
  31. t.pencolor(255,155,192)
  32. t.seth(10)
  33. t.begin_fill()
  34. t.circle(5)
  35. t.color(160,82,45)
  36. t.end_fill()
  37. t.pu()
  38. t.seth(0)
  39. t.fd(20)
  40. t.pd()
  41. t.pencolor(255,155,192)
  42. t.seth(10)
  43. t.begin_fill()
  44. t.circle(5)
  45. t.color(160,82,45)
  46. t.end_fill()
  47. #頭
  48. t.color((255,155,192),"pink")
  49. t.pu()
  50. t.seth(90)
  51. t.fd(41)
  52. t.seth(0)
  53. t.fd(0)
  54. t.pd()
  55. t.begin_fill()
  56. t.seth(180)
  57. t.circle(300,-30)
  58. t.circle(100,-60)
  59. t.circle(80,-100)
  60. t.circle(150,-20)
  61. t.circle(60,-95)
  62. t.seth(161)
  63. t.circle(-300,15)
  64. t.pu()
  65. t.goto(-100,100)
  66. t.pd()
  67. t.seth(-30)
  68. a=0.4
  69. for

    i

    in

    range(60):
  70. if

    0<=i<30

    or

    60<=i<90:
  71. a=a+0.08
  72. t.lt(3) #向左轉3度
  73. t.fd(a) #向前走a的步長
  74. else

    :

  75. a=a-0.08
  76. t.lt(3)
  77. t.fd(a)
  78. t.end_fill()
  79. #耳朵
  80. t.color((255,155,192),"pink")
  81. t.pu()
  82. t.seth(90)
  83. t.fd(-7)
  84. t.seth(0)
  85. t.fd(70)
  86. t.pd()
  87. t.begin_fill()
  88. t.seth(100)
  89. t.circle(-50,50)
  90. t.circle(-10,120)
  91. t.circle(-50,54)
  92. t.end_fill()
  93. t.pu()
  94. t.seth(90)
  95. t.fd(-12)
  96. t.seth(0)
  97. t.fd(30)
  98. t.pd()
  99. t.begin_fill()
  100. t.seth(100)
  101. t.circle(-50,50)
  102. t.circle(-10,120)
  103. t.circle(-50,56)
  104. t.end_fill()
  105. #眼睛
  106. t.color((255,155,192),"white")
  107. t.pu()
  108. t.seth(90)
  109. t.fd(-20)
  110. t.seth(0)
  111. t.fd(-95)
  112. t.pd()
  113. t.begin_fill()
  114. t.circle(15)
  115. t.end_fill()
  116. t.color("black")
  117. t.pu()
  118. t.seth(90)
  119. t.fd(12)
  120. t.seth(0)
  121. t.fd(-3)
  122. t.pd()
  123. t.begin_fill()
  124. t.circle(3)
  125. t.end_fill()
  126. t.color((255,155,192),"white")
  127. t.pu()
  128. t.seth(90)
  129. t.fd(-25)
  130. t.seth(0)
  131. t.fd(40)
  132. t.pd()
  133. t.begin_fill()
  134. t.circle(15)
  135. t.end_fill()
  136. t.color("black")
  137. t.pu()
  138. t.seth(90)
  139. t.fd(12)
  140. t.seth(0)
  141. t.fd(-3)
  142. t.pd()
  143. t.begin_fill()
  144. t.circle(3)
  145. t.end_fill()
  146. #腮
  147. t.color((255,155,192))
  148. t.pu()
  149. t.seth(90)
  150. t.fd(-95)
  151. t.seth(0)
  152. t.fd(65)
  153. t.pd()
  154. t.begin_fill()
  155. t.circle(30)
  156. t.end_fill()
  157. #嘴
  158. t.color(239,69,19)
  159. t.pu()
  160. t.seth(90)
  161. t.fd(15)
  162. t.seth(0)
  163. t.fd(-100)
  164. t.pd()
  165. t.seth(-80)
  166. t.circle(30,40)
  167. t.circle(40,80)
  168. #身體
  169. t.color("red",(255,99,71))
  170. t.pu()
  171. t.seth(90)
  172. t.fd(-20)
  173. t.seth(0)
  174. t.fd(-78)
  175. t.pd()
  176. t.begin_fill()
  177. t.seth(-130)
  178. t.circle(100,10)
  179. t.circle(300,30)
  180. t.seth(0)
  181. t.fd(230)
  182. t.seth(90)
  183. t.circle(300,30)
  184. t.circle(100,3)
  185. t.color((255,155,192),(255,100,100))
  186. t.seth(-135)
  187. t.circle(-80,63)
  188. t.circle(-150,24)
  189. t.end_fill()
  190. #手
  191. t.color((255,155,192))
  192. t.pu()
  193. t.seth(90)
  194. t.fd(-40)
  195. t.seth(0)
  196. t.fd(-27)
  197. t.pd()
  198. t.seth(-160)
  199. t.circle(300,15)
  200. t.pu()
  201. t.seth(90)
  202. t.fd(15)
  203. t.seth(0)
  204. t.fd(0)
  205. t.pd()
  206. t.seth(-10)
  207. t.circle(-20,90)
  208. t.pu()
  209. t.seth(90)
  210. t.fd(30)
  211. t.seth(0)
  212. t.fd(237)
  213. t.pd()
  214. t.seth(-20)
  215. t.circle(-300,15)
  216. t.pu()
  217. t.seth(90)
  218. t.fd(20)
  219. t.seth(0)
  220. t.fd(0)
  221. t.pd()
  222. t.seth(-170)
  223. t.circle(20,90)
  224. #腳
  225. t.pensize(10)
  226. t.color((240,128,128))
  227. t.pu()
  228. t.seth(90)
  229. t.fd(-75)
  230. t.seth(0)
  231. t.fd(-180)
  232. t.pd()
  233. t.seth(-90)
  234. t.fd(40)
  235. t.seth(-180)
  236. t.color("black")
  237. t.pensize(15)
  238. t.fd(20)
  239. t.pensize(10)
  240. t.color((240,128,128))
  241. t.pu()
  242. t.seth(90)
  243. t.fd(40)
  244. t.seth(0)
  245. t.fd(90)
  246. t.pd()
  247. t.seth(-90)
  248. t.fd(40)
  249. t.seth(-180)
  250. t.color("black")
  251. t.pensize(15)
  252. t.fd(20)
  253. #尾巴
  254. t.pensize(4)
  255. t.color((255,155,192))
  256. t.pu()
  257. t.seth(90)
  258. t.fd(70)
  259. t.seth(0)
  260. t.fd(95)
  261. t.pd()
  262. t.seth(0)
  263. t.circle(70,20)
  264. t.circle(10,330)
  265. t.circle(70,30)

用python實現小豬佩奇

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

XSLT <xsl:template> 元素

TAG:程序員小新人學習 |