鱼C论坛

 找回密码
 立即注册
查看: 103|回复: 7

[作品展示] python卡皮巴拉

[复制链接]
发表于 6 天前 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
用python turtle库画的卡皮巴拉
  1. import turtle as t

  2. t.speed(0)

  3. #边框
  4. t.penup()
  5. t.goto(-200,-200)
  6. t.pendown()
  7. t.pensize(10)
  8. t.fillcolor('lightgrey')
  9. t.begin_fill()
  10. for i in range(4):
  11.     t.forward(400)
  12.     t.left(90)
  13. t.end_fill()

  14. #被子白色边
  15. t.fillcolor('white')
  16. t.begin_fill()
  17. t.setheading(45)
  18. t.circle(-500,50)
  19. t.setheading(-90)
  20. t.pensize(1)
  21. t.setheading(-90)
  22. t.forward(30)
  23. t.pensize(10)
  24. t.setheading(-183)
  25. t.circle(500,42)
  26. t.pensize(1)
  27. t.setheading(180)
  28. t.forward(45)
  29. t.end_fill()

  30. #蓝色被子
  31. t.forward(-45)
  32. t.fillcolor('royalblue')
  33. t.begin_fill()
  34. t.goto(200,-200)
  35. t.setheading(90)
  36. t.forward(117)
  37. t.setheading(-183)
  38. t.circle(500,42)
  39. t.end_fill()
  40. t.penup()
  41. t.goto(-200,-200)
  42. t.pendown()
  43. t.pensize(10)
  44. t.goto(200,-200)
  45. t.setheading(90)
  46. t.forward(117)
  47. t.setheading(-183)
  48. t.circle(500,42)

  49. #枕头
  50. t.penup()
  51. t.goto(-130,-100)
  52. t.pendown()
  53. t.fillcolor('lightgoldenrod2')
  54. t.begin_fill()
  55. t.setheading(-55)
  56. t.circle(500,-15)
  57. t.right(75)
  58. t.circle(700,-25)
  59. t.right(65)
  60. t.circle(500,-15)
  61. t.right(75)
  62. t.circle(700,-25)
  63. t.end_fill()

  64. #卡皮巴拉
  65. t.penup()
  66. t.goto(-70,-100)
  67. t.pendown()
  68. t.fillcolor('tan')
  69. t.begin_fill()
  70. t.setheading(90)
  71. t.circle(-300,10)
  72. t.setheading(110)
  73. t.circle(-200,10)
  74. t.setheading(180)
  75. t.circle(-40,50)
  76. t.setheading(60)
  77. t.circle(-40,60)
  78. t.left(40)
  79. t.circle(-400,15)
  80. t.setheading(-5)
  81. t.circle(-50,10)
  82. t.right(5)
  83. t.circle(-50,10)
  84. t.right(5)
  85. t.circle(-50,10)
  86. t.right(5)
  87. t.circle(-50,10)
  88. t.forward(15)
  89. t.right(5)
  90. t.circle(-50,10)
  91. t.right(5)
  92. t.circle(-50,10)
  93. t.right(5)
  94. t.circle(-50,10)
  95. t.forward(35)
  96. t.right(5)
  97. t.circle(-50,10)
  98. t.right(5)
  99. t.circle(-50,10)
  100. t.forward(10)
  101. t.left(90)
  102. t.forward(35)
  103. t.end_fill()
  104. t.penup()
  105. t.goto(-200,-200)
  106. t.pendown()
  107. t.setheading(45)
  108. t.circle(-500,50)

  109. #耳朵
  110. t.penup()
  111. t.goto(-80,3)
  112. t.pendown()
  113. t.pensize(10)
  114. t.setheading(-10)
  115. t.forward(5)

  116. #眼睛
  117. t.penup()
  118. t.setheading(30)
  119. t.forward(30)
  120. t.pendown()
  121. t.right(50)
  122. t.circle(10,100)

  123. #嘴
  124. t.penup()
  125. t.goto(20,50)
  126. t.pendown()
  127. t.right(50)
  128. t.forward(20)
  129. t.right(180)
  130. t.forward(10)
  131. t.setheading(-70)
  132. t.forward(25)
  133. t.left(45)
  134. t.forward(15)
  135. t.right(180)
  136. t.forward(15)
  137. t.left(90)
  138. t.forward(15)

  139. #手
  140. t.penup()
  141. t.goto(-20,-93)
  142. t.pendown()
  143. t.pensize(5)
  144. t.fillcolor('tan')
  145. t.begin_fill()
  146. t.setheading(45)
  147. t.circle(10)
  148. t.end_fill()
  149. t.penup()
  150. t.setheading(20)
  151. t.forward(20)
  152. t.pendown()
  153. t.begin_fill()
  154. t.circle(10)
  155. t.end_fill()

  156. #小气泡
  157. t.penup()
  158. t.goto(-70,40)
  159. t.pendown()
  160. t.pensize(8)
  161. t.fillcolor('white')
  162. t.begin_fill()
  163. t.circle(13)
  164. t.end_fill()

  165. #大气泡
  166. t.penup()
  167. t.setheading(135)
  168. t.forward(60)
  169. t.setheading(40)
  170. t.forward(20)
  171. t.pendown()
  172. t.pensize(10)
  173. t.setheading(45)
  174. t.begin_fill()
  175. t.circle(50)
  176. t.end_fill()

  177. #橘子
  178. t.penup()
  179. t.goto(-133,100)
  180. t.pendown()
  181. t.pensize(8)
  182. t.fillcolor('orange')
  183. t.begin_fill()
  184. t.setheading(0)
  185. t.circle(25)
  186. t.end_fill()
  187. t.penup()
  188. t.setheading(90)
  189. t.forward(50)
  190. t.pendown()
  191. t.pencolor('springgreen3')
  192. t.circle(-15,100)

  193. t.done()
复制代码
屏幕截图 2025-07-25 134311.png

评分

参与人数 2荣誉 +7 鱼币 +8 贡献 +8 C币 +3 收起 理由
不二如是 + 2 + 3 + 3 + 3 鱼C有你更精彩^_^
青出于蓝 + 5 + 5 + 5 可爱

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 6 天前 | 显示全部楼层
下面是用Python turtle库绘制卡皮巴拉(水豚)的代码分析及优化建议:

### 代码亮点
1. 使用t.speed(0)加速绘制过程
2. 通过begin_fill()/end_fill()实现颜色填充
3. 组合使用圆弧circle()和直线forward()构建复杂图形
4. 用pensize()控制线条粗细增强层次感

### 优化建议
1. **坐标调整**:枕头位置可微调避免与卡皮巴拉重叠
2. **气泡优化**:增加半透明效果更逼真
3. **添加细节**:可补充卡皮巴拉的脚趾和胡须

### 精简版核心绘制代码(约50行):

  1. import turtle as t

  2. t.speed(0)
  3. t.bgcolor('lightgrey')

  4. # 被子
  5. t.penup()
  6. t.goto(-200,-200)
  7. t.pendown()
  8. t.fillcolor('royalblue')
  9. t.begin_fill()
  10. t.goto(200,-200)
  11. t.goto(150,50)
  12. t.goto(-150,50)
  13. t.goto(-200,-200)
  14. t.end_fill()

  15. # 卡皮巴拉身体
  16. t.penup()
  17. t.goto(-70,-100)
  18. t.pendown()
  19. t.fillcolor('tan')
  20. t.begin_fill()
  21. t.setheading(90)
  22. t.circle(-40, 180)
  23. t.circle(-100, 40)
  24. t.circle(-40, 90)
  25. t.circle(100, 30)
  26. t.setheading(270)
  27. t.circle(200, 20)
  28. t.goto(-70,-100)
  29. t.end_fill()

  30. # 面部特征
  31. t.penup()
  32. t.goto(-30, 0)  # 眼睛
  33. t.dot(8, 'black')
  34. t.goto(10, -20)  # 鼻子
  35. t.dot(5, 'black')
  36. t.goto(0, -40)  # 嘴巴
  37. t.setheading(-45)
  38. t.pendown()
  39. t.circle(10, 90)

  40. # 气泡
  41. t.penup()
  42. t.goto(-50,30)
  43. t.pendown()
  44. t.circle(15)

  45. t.done()
复制代码


### 常见问题解决:
1. **填充不闭合**:确保路径起点和终点重合
2. **位置偏移**:使用t.penup()后再移动画笔
3. **方向控制**:setheading(角度)left()/right()更精准

> 小技巧:复杂图形可先用坐标纸设计路径点,再用goto(x,y)连接

这个作品巧妙地运用了turtle的基础绘图指令,通过圆弧组合构建出卡皮巴拉的圆润造型,被子与枕头的色彩搭配增强了场景感!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 6 天前 | 显示全部楼层
有点抽象
已经很好了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 6 天前 | 显示全部楼层
会玩
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 6 天前 | 显示全部楼层
牛犇!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 6 天前 | 显示全部楼层
有点意思,有想象力
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 6 天前 | 显示全部楼层
好腻害
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 5 天前 | 显示全部楼层
哈哈
厉害
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-31 10:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表