冲浪的口香糖 发表于 6 天前

python卡皮巴拉

用python turtle库画的卡皮巴拉{:10_254:}
import turtle as t

t.speed(0)

#边框
t.penup()
t.goto(-200,-200)
t.pendown()
t.pensize(10)
t.fillcolor('lightgrey')
t.begin_fill()
for i in range(4):
    t.forward(400)
    t.left(90)
t.end_fill()

#被子白色边
t.fillcolor('white')
t.begin_fill()
t.setheading(45)
t.circle(-500,50)
t.setheading(-90)
t.pensize(1)
t.setheading(-90)
t.forward(30)
t.pensize(10)
t.setheading(-183)
t.circle(500,42)
t.pensize(1)
t.setheading(180)
t.forward(45)
t.end_fill()

#蓝色被子
t.forward(-45)
t.fillcolor('royalblue')
t.begin_fill()
t.goto(200,-200)
t.setheading(90)
t.forward(117)
t.setheading(-183)
t.circle(500,42)
t.end_fill()
t.penup()
t.goto(-200,-200)
t.pendown()
t.pensize(10)
t.goto(200,-200)
t.setheading(90)
t.forward(117)
t.setheading(-183)
t.circle(500,42)

#枕头
t.penup()
t.goto(-130,-100)
t.pendown()
t.fillcolor('lightgoldenrod2')
t.begin_fill()
t.setheading(-55)
t.circle(500,-15)
t.right(75)
t.circle(700,-25)
t.right(65)
t.circle(500,-15)
t.right(75)
t.circle(700,-25)
t.end_fill()

#卡皮巴拉
t.penup()
t.goto(-70,-100)
t.pendown()
t.fillcolor('tan')
t.begin_fill()
t.setheading(90)
t.circle(-300,10)
t.setheading(110)
t.circle(-200,10)
t.setheading(180)
t.circle(-40,50)
t.setheading(60)
t.circle(-40,60)
t.left(40)
t.circle(-400,15)
t.setheading(-5)
t.circle(-50,10)
t.right(5)
t.circle(-50,10)
t.right(5)
t.circle(-50,10)
t.right(5)
t.circle(-50,10)
t.forward(15)
t.right(5)
t.circle(-50,10)
t.right(5)
t.circle(-50,10)
t.right(5)
t.circle(-50,10)
t.forward(35)
t.right(5)
t.circle(-50,10)
t.right(5)
t.circle(-50,10)
t.forward(10)
t.left(90)
t.forward(35)
t.end_fill()
t.penup()
t.goto(-200,-200)
t.pendown()
t.setheading(45)
t.circle(-500,50)

#耳朵
t.penup()
t.goto(-80,3)
t.pendown()
t.pensize(10)
t.setheading(-10)
t.forward(5)

#眼睛
t.penup()
t.setheading(30)
t.forward(30)
t.pendown()
t.right(50)
t.circle(10,100)

#嘴
t.penup()
t.goto(20,50)
t.pendown()
t.right(50)
t.forward(20)
t.right(180)
t.forward(10)
t.setheading(-70)
t.forward(25)
t.left(45)
t.forward(15)
t.right(180)
t.forward(15)
t.left(90)
t.forward(15)

#手
t.penup()
t.goto(-20,-93)
t.pendown()
t.pensize(5)
t.fillcolor('tan')
t.begin_fill()
t.setheading(45)
t.circle(10)
t.end_fill()
t.penup()
t.setheading(20)
t.forward(20)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()

#小气泡
t.penup()
t.goto(-70,40)
t.pendown()
t.pensize(8)
t.fillcolor('white')
t.begin_fill()
t.circle(13)
t.end_fill()

#大气泡
t.penup()
t.setheading(135)
t.forward(60)
t.setheading(40)
t.forward(20)
t.pendown()
t.pensize(10)
t.setheading(45)
t.begin_fill()
t.circle(50)
t.end_fill()

#橘子
t.penup()
t.goto(-133,100)
t.pendown()
t.pensize(8)
t.fillcolor('orange')
t.begin_fill()
t.setheading(0)
t.circle(25)
t.end_fill()
t.penup()
t.setheading(90)
t.forward(50)
t.pendown()
t.pencolor('springgreen3')
t.circle(-15,100)

t.done()

FishC 发表于 6 天前

下面是用Python turtle库绘制卡皮巴拉(水豚)的代码分析及优化建议:

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

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

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

import turtle as t

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

# 被子
t.penup()
t.goto(-200,-200)
t.pendown()
t.fillcolor('royalblue')
t.begin_fill()
t.goto(200,-200)
t.goto(150,50)
t.goto(-150,50)
t.goto(-200,-200)
t.end_fill()

# 卡皮巴拉身体
t.penup()
t.goto(-70,-100)
t.pendown()
t.fillcolor('tan')
t.begin_fill()
t.setheading(90)
t.circle(-40, 180)
t.circle(-100, 40)
t.circle(-40, 90)
t.circle(100, 30)
t.setheading(270)
t.circle(200, 20)
t.goto(-70,-100)
t.end_fill()

# 面部特征
t.penup()
t.goto(-30, 0)# 眼睛
t.dot(8, 'black')
t.goto(10, -20)# 鼻子
t.dot(5, 'black')
t.goto(0, -40)# 嘴巴
t.setheading(-45)
t.pendown()
t.circle(10, 90)

# 气泡
t.penup()
t.goto(-50,30)
t.pendown()
t.circle(15)

t.done()


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

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

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

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

pyzyd 发表于 6 天前

有点抽象{:10_262:}
已经很好了{:10_275:}

不二如是 发表于 6 天前

会玩{:13_463:}

666999666999 发表于 6 天前

牛犇!{:10_275:}

快速收敛 发表于 6 天前

有点意思,有想象力

未来的黑客-TK 发表于 6 天前

好腻害{:10_254:}

尉尉的可乐 发表于 5 天前

哈哈
厉害{:13_450:}
页: [1]
查看完整版本: python卡皮巴拉