peppa_pig.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. """
  2. 绘制小猪佩奇
  3. """
  4. from turtle import *
  5. def nose(x,y):
  6. """画鼻子"""
  7. penup()
  8. # 将海龟移动到指定的坐标
  9. goto(x,y)
  10. pendown()
  11. # 设置海龟的方向(0-东、90-北、180-西、270-南)
  12. setheading(-30)
  13. 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. # 向左转3度
  19. left(3)
  20. # 向前走
  21. forward(a)
  22. else:
  23. a = a - 0.08
  24. left(3)
  25. forward(a)
  26. end_fill()
  27. penup()
  28. setheading(90)
  29. forward(25)
  30. setheading(0)
  31. forward(10)
  32. pendown()
  33. # 设置画笔的颜色(红, 绿, 蓝)
  34. pencolor(255, 155, 192)
  35. setheading(10)
  36. begin_fill()
  37. circle(5)
  38. color(160, 82, 45)
  39. end_fill()
  40. penup()
  41. setheading(0)
  42. forward(20)
  43. pendown()
  44. pencolor(255, 155, 192)
  45. setheading(10)
  46. begin_fill()
  47. circle(5)
  48. color(160, 82, 45)
  49. end_fill()
  50. def head(x, y):
  51. """画头"""
  52. color((255, 155, 192), "pink")
  53. penup()
  54. goto(x,y)
  55. setheading(0)
  56. pendown()
  57. begin_fill()
  58. setheading(180)
  59. circle(300, -30)
  60. circle(100, -60)
  61. circle(80, -100)
  62. circle(150, -20)
  63. circle(60, -95)
  64. setheading(161)
  65. circle(-300, 15)
  66. penup()
  67. goto(-100, 100)
  68. pendown()
  69. setheading(-30)
  70. a = 0.4
  71. for i in range(60):
  72. if 0<= i < 30 or 60 <= i < 90:
  73. a = a + 0.08
  74. lt(3) #向左转3度
  75. fd(a) #向前走a的步长
  76. else:
  77. a = a - 0.08
  78. lt(3)
  79. fd(a)
  80. end_fill()
  81. def ears(x,y):
  82. """画耳朵"""
  83. color((255, 155, 192), "pink")
  84. penup()
  85. goto(x, y)
  86. pendown()
  87. begin_fill()
  88. setheading(100)
  89. circle(-50, 50)
  90. circle(-10, 120)
  91. circle(-50, 54)
  92. end_fill()
  93. penup()
  94. setheading(90)
  95. forward(-12)
  96. setheading(0)
  97. forward(30)
  98. pendown()
  99. begin_fill()
  100. setheading(100)
  101. circle(-50, 50)
  102. circle(-10, 120)
  103. circle(-50, 56)
  104. end_fill()
  105. def eyes(x,y):
  106. """画眼睛"""
  107. color((255, 155, 192), "white")
  108. penup()
  109. setheading(90)
  110. forward(-20)
  111. setheading(0)
  112. forward(-95)
  113. pendown()
  114. begin_fill()
  115. circle(15)
  116. end_fill()
  117. color("black")
  118. penup()
  119. setheading(90)
  120. forward(12)
  121. setheading(0)
  122. forward(-3)
  123. pendown()
  124. begin_fill()
  125. circle(3)
  126. end_fill()
  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. color("black")
  138. penup()
  139. setheading(90)
  140. forward(12)
  141. setheading(0)
  142. forward(-3)
  143. pendown()
  144. begin_fill()
  145. circle(3)
  146. end_fill()
  147. def cheek(x,y):
  148. """画脸颊"""
  149. color((255, 155, 192))
  150. penup()
  151. goto(x,y)
  152. pendown()
  153. setheading(0)
  154. begin_fill()
  155. circle(30)
  156. end_fill()
  157. def mouth(x,y):
  158. """画嘴巴"""
  159. color(239, 69, 19)
  160. penup()
  161. goto(x, y)
  162. pendown()
  163. setheading(-80)
  164. circle(30, 40)
  165. circle(40, 80)
  166. def setting():
  167. """设置参数"""
  168. pensize(4)
  169. # 隐藏海龟
  170. hideturtle()
  171. colormode(255)
  172. color((255, 155, 192), "pink")
  173. setup(840, 500)
  174. speed(10)
  175. def main():
  176. """主函数"""
  177. setting()
  178. nose(-100, 100)
  179. head(-69, 167)
  180. ears(0, 160)
  181. eyes(0, 140)
  182. cheek(80, 10)
  183. mouth(-20, 30)
  184. done()
  185. if __name__ == '__main__':
  186. main()