当前位置:   article > 正文

Python动态画图小代码(Turtle Graphics)_turtle画图作品代码

turtle画图作品代码

1. 穿雨鞋的小黄鸭

  1. from turtle import *
  2. #扁嘴
  3. pensize(2)
  4. pu()
  5. goto(-100,100)#上嘴最高顶点
  6. seth(-50)
  7. pd()
  8. color('#6C3100','#FADD77')
  9. begin_fill()
  10. fd(16)
  11. vertex_right = pos()#嘴最右顶点
  12. rt(50)
  13. fd(12)
  14. vertex_down = pos()#下嘴最低顶点
  15. rt(80)
  16. fd(30)
  17. circle(-3,200)
  18. vertex_left = pos()#嘴最左顶点
  19. goto(-100,100)
  20. end_fill()
  21. goto(vertex_left)#回到最左顶点
  22. circle(-3,-200)#扁嘴
  23. goto(vertex_right)
  24. #身体
  25. #头颈背尾曲线
  26. color('#B6A88E')
  27. pu()
  28. goto(-100,100)
  29. pd()
  30. seth(80)
  31. circle(-36,160)
  32. fd(25)
  33. circle(115,20)
  34. circle(60,55)
  35. circle(-200,20)
  36. circle(110,20)
  37. color('#7D6A4C')
  38. circle(40,40)
  39. color('#B6A88E')
  40. seth(-100)
  41. circle(-180,30)
  42. circle(-20,50)
  43. #右鸭腿
  44. circle(20,70)
  45. color('#736856')
  46. circle(-12,120)
  47. leg_pos1 = pos()#定位左腿位置
  48. fd(25)
  49. #前胸肚曲线
  50. pu()
  51. goto(vertex_down)
  52. pd()
  53. seth(-10)
  54. color('#B9AD9D')
  55. circle(-40,50)
  56. circle(-80,48)
  57. color('#736856')
  58. circle(250,5)
  59. circle(50,75)
  60. color('#B9AD9D')
  61. circle(220,28)
  62. #左鸭腿
  63. pu()
  64. seth(175)
  65. fd(40)
  66. pd()
  67. seth(-120)
  68. fd(8)
  69. circle(-10,120)
  70. leg_pos2 = pos()#定位右腿位置
  71. fd(15)
  72. #眼睛
  73. color('black')
  74. #左眼
  75. pu()
  76. goto(vertex_down - (1,-29))
  77. pd()
  78. dot(4,'black')#相比circle(),不需要再额外填充颜色
  79. #右眼
  80. pu()
  81. goto(vertex_down + (23,20))
  82. pd()
  83. dot(4,'black')
  84. #翅膀
  85. color('#BCB2A6')
  86. pu()
  87. goto(vertex_down - (-75,130))
  88. seth(130)
  89. pd()
  90. circle(-25,130)
  91. circle(-100,30)
  92. fd(85)
  93. point = pos()
  94. rt(137)
  95. fd(52)
  96. circle(-100,58)
  97. pu()
  98. goto(point)
  99. lt(30)
  100. pd()
  101. fd(60)
  102. pu()
  103. goto(point)
  104. pd()
  105. lt(10)
  106. fd(70)
  107. #腿部
  108. #左腿
  109. def leg(pos0):#鸭腿绘制函数
  110. pensize(8)
  111. color('#ECC578')
  112. pu()
  113. goto(pos0)
  114. seth(0)
  115. fd(7)
  116. seth(-90)
  117. fd(8.5)
  118. pd()
  119. fd(20)#腿长
  120. leg(leg_pos1)
  121. leg(leg_pos2)
  122. #小红靴——函数
  123. def boot(pos0):
  124. pensize(2)
  125. color('#B4070B','#FBA06B')
  126. pu()
  127. goto(pos0)#靴子右上顶点
  128. pd()
  129. begin_fill()
  130. seth(140)
  131. circle(25,80)
  132. seth(-80)
  133. fd(35)#fd(30)左侧线条
  134. circle(-2,60)#靴低
  135. fd(20)
  136. circle(4,180)
  137. seth(5)
  138. fd(30)
  139. circle(2,60)
  140. goto(pos0)#右侧线条
  141. end_fill()
  142. boot(leg_pos1-(-20,30))
  143. boot(leg_pos2-(-20,30))
  144. #小雨滴
  145. color('#77DDFF','#D8E8E5')
  146. fd_ls = [200,140,250,240,230,220,180,250]
  147. lt_ls = [30,60,60,100,125,170,200,330]
  148. for i in range(8):
  149. pu()
  150. home()
  151. lt(lt_ls[i])
  152. fd(fd_ls[i])
  153. pd()
  154. seth(-78)
  155. fd(15)
  156. begin_fill()
  157. circle(-3,200)
  158. end_fill()
  159. fd(15)
  160. #文字
  161. pu()
  162. goto(vertex_left)
  163. seth(180)
  164. fd(150)
  165. seth(-90)
  166. fd(300)
  167. color('black')
  168. write('code by totoup',font=("Arial",15,"normal"))
  169. hideturtle()
  170. done()

2.告白(一) 

  1. import turtle
  2. import time
  3. # 清屏函数
  4. def clear_all():
  5. turtle.penup()
  6. turtle.goto(0, 0)
  7. turtle.color('white')
  8. turtle.pensize(800)
  9. turtle.pendown()
  10. turtle.setheading(0)
  11. turtle.fd(300)
  12. turtle.bk(600)
  13. # 重定位海龟的位置
  14. def go_to(x, y, state):
  15. turtle.pendown() if state else turtle.penup()
  16. turtle.goto(x, y)
  17. # 画线
  18. # state为真时海龟回到原点,为假时不回到原来的出发点
  19. def draw_line(length, angle, state):
  20. turtle.pensize(1)
  21. turtle.pendown()
  22. turtle.setheading(angle)
  23. turtle.fd(length)
  24. turtle.bk(length) if state else turtle.penup()
  25. turtle.penup()
  26. # 画箭羽
  27. def draw_feather(size):
  28. angle = 30 # 箭的倾角
  29. feather_num = size//6 # 羽毛的数量
  30. feather_length = size // 3 # 羽毛的长度
  31. feather_gap = size//10 # 羽毛的间隔
  32. for i in range(feather_num):
  33. draw_line(feather_gap, angle+180, False) # 箭柄,不折返
  34. draw_line(feather_length, angle + 145, True) # 羽翼,要折返
  35. draw_line(feather_length, angle + 145, False)
  36. draw_line(feather_num*feather_gap, angle, False)
  37. draw_line(feather_length, angle + 145 + 180, False)
  38. for i in range(feather_num):
  39. draw_line(feather_gap, angle+180, False) # 箭柄,不折返
  40. draw_line(feather_length, angle - 145, True) # 羽翼,要折返
  41. draw_line(feather_length, angle - 145, False)
  42. draw_line(feather_num*feather_gap, angle, False)
  43. draw_line(feather_length, angle - 145 + 180, False)
  44. # 画爱心
  45. def draw_heart(size):
  46. turtle.color('red', 'pink')
  47. turtle.pensize(2)
  48. turtle.pendown()
  49. turtle.seth
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/968953
推荐阅读
相关标签
  

闽ICP备14008679号