peppa_pig.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. from turtle import*
  2. def nose(x,y):#鼻子
  3. penup()#提起笔
  4. goto(x,y)#定位
  5. pendown()#落笔,开始画
  6. setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
  7. begin_fill()#准备开始填充图形
  8. a=0.4
  9. for i in range(120):
  10. if 0<=i<30 or 60<=i<90:
  11. a=a+0.08
  12. left(3) #向左转3度
  13. forward(a) #向前走a的步长
  14. else:
  15. a=a-0.08
  16. left(3)
  17. forward(a)
  18. end_fill()#填充完成
  19. penup()
  20. setheading(90)
  21. forward(25)
  22. setheading(0)
  23. forward(10)
  24. pendown()
  25. pencolor(255,155,192)#画笔颜色
  26. setheading(10)
  27. begin_fill()
  28. circle(5)
  29. color(160,82,45)#返回或设置pencolor和fillcolor
  30. end_fill()
  31. penup()
  32. setheading(0)
  33. forward(20)
  34. pendown()
  35. pencolor(255,155,192)
  36. setheading(10)
  37. begin_fill()
  38. circle(5)
  39. color(160,82,45)
  40. end_fill()
  41. def head(x,y):#头
  42. color((255,155,192),"pink")
  43. penup()
  44. goto(x,y)
  45. setheading(0)
  46. pendown()
  47. begin_fill()
  48. setheading(180)
  49. circle(300,-30)
  50. circle(100,-60)
  51. circle(80,-100)
  52. circle(150,-20)
  53. circle(60,-95)
  54. setheading(161)
  55. circle(-300,15)
  56. penup()
  57. goto(-100,100)
  58. pendown()
  59. setheading(-30)
  60. a=0.4
  61. for i in range(60):
  62. if 0<=i<30 or 60<=i<90:
  63. a=a+0.08
  64. lt(3) #向左转3度
  65. fd(a) #向前走a的步长
  66. else:
  67. a=a-0.08
  68. lt(3)
  69. fd(a)
  70. end_fill()
  71. def ears(x,y): #耳朵
  72. color((255,155,192),"pink")
  73. penup()
  74. goto(x,y)
  75. pendown()
  76. begin_fill()
  77. setheading(100)
  78. circle(-50,50)
  79. circle(-10,120)
  80. circle(-50,54)
  81. end_fill()
  82. penup()
  83. setheading(90)
  84. forward(-12)
  85. setheading(0)
  86. forward(30)
  87. pendown()
  88. begin_fill()
  89. setheading(100)
  90. circle(-50,50)
  91. circle(-10,120)
  92. circle(-50,56)
  93. end_fill()
  94. def eyes(x,y):#眼睛
  95. color((255,155,192),"white")
  96. penup()
  97. setheading(90)
  98. forward(-20)
  99. setheading(0)
  100. forward(-95)
  101. pendown()
  102. begin_fill()
  103. circle(15)
  104. end_fill()
  105. color("black")
  106. penup()
  107. setheading(90)
  108. forward(12)
  109. setheading(0)
  110. forward(-3)
  111. pendown()
  112. begin_fill()
  113. circle(3)
  114. end_fill()
  115. color((255,155,192),"white")
  116. penup()
  117. seth(90)
  118. forward(-25)
  119. seth(0)
  120. forward(40)
  121. pendown()
  122. begin_fill()
  123. circle(15)
  124. end_fill()
  125. color("black")
  126. penup()
  127. setheading(90)
  128. forward(12)
  129. setheading(0)
  130. forward(-3)
  131. pendown()
  132. begin_fill()
  133. circle(3)
  134. end_fill()
  135. def cheek(x,y):#腮
  136. color((255,155,192))
  137. penup()
  138. goto(x,y)
  139. pendown()
  140. setheading(0)
  141. begin_fill()
  142. circle(30)
  143. end_fill()
  144. def mouth(x,y): #嘴
  145. color(239,69,19)
  146. penup()
  147. goto(x,y)
  148. pendown()
  149. setheading(-80)
  150. circle(30,40)
  151. circle(40,80)
  152. def setting(): #参数设置
  153. pensize(4)
  154. hideturtle() #使乌龟无形(隐藏)
  155. colormode(255) #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内
  156. color((255,155,192),"pink")
  157. setup(840,500)
  158. speed(10)
  159. def main():
  160. setting() #画布、画笔设置
  161. nose(-100,100) #鼻子
  162. head(-69,167) #头
  163. ears(0,160) #耳朵
  164. eyes(0,140) #眼睛
  165. cheek(80,10) #腮
  166. mouth(-20,30) #嘴
  167. done()
  168. if __name__ == '__main__':
  169. main()