python的turtle画一个凯蒂猫
时间: 2023-11-11 09:06:16 浏览: 178
以下是用Python的turtle库画出一个卡通猫(Kitty Cat)的示例代码:
```python
import turtle
# 设置画笔颜色和粗细
turtle.pensize(4)
turtle.pencolor("black")
# 绘制头部
turtle.fillcolor("#FFD1DC")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 绘制左耳朵
turtle.fillcolor("#FFD1DC")
turtle.begin_fill()
turtle.penup()
turtle.goto(-50, 220)
turtle.pendown()
turtle.right(30)
turtle.circle(50, 270)
turtle.left(60)
turtle.circle(20, 180)
turtle.left(60)
turtle.circle(50, 270)
turtle.end_fill()
# 绘制右耳朵
turtle.fillcolor("#FFD1DC")
turtle.begin_fill()
turtle.penup()
turtle.goto(50, 220)
turtle.pendown()
turtle.left(30)
turtle.circle(-50, 270)
turtle.right(60)
turtle.circle(-20, 180)
turtle.right(60)
turtle.circle(-50, 270)
turtle.end_fill()
# 绘制左眼
turtle.fillcolor("white")
turtle.begin_fill()
turtle.penup()
turtle.goto(-40, 70)
turtle.pendown()
turtle.circle(20)
turtle.end_fill()
# 绘制右眼
turtle.fillcolor("white")
turtle.begin_fill()
turtle.penup()
turtle.goto(40, 70)
turtle.pendown()
turtle.circle(20)
turtle.end_fill()
# 绘制左眼珠
turtle.fillcolor("black")
turtle.begin_fill()
turtle.penup()
turtle.goto(-40, 70)
turtle.pendown()
turtle.circle(10)
turtle.end_fill()
# 绘制右眼珠
turtle.fillcolor("black")
turtle.begin_fill()
turtle.penup()
turtle.goto(40, 70)
turtle.pendown()
turtle.circle(10)
turtle.end_fill()
# 绘制鼻子
turtle.fillcolor("#FFD1DC")
turtle.begin_fill()
turtle.penup()
turtle.goto(0, 20)
turtle.pendown()
turtle.circle(30)
turtle.end_fill()
# 绘制嘴巴
turtle.penup()
turtle.goto(-20, -30)
turtle.pendown()
turtle.right(20)
turtle.circle(70, 140)
# 绘制胡须
turtle.penup()
turtle.goto(-35, 0)
turtle.pendown()
turtle.goto(-100, 20)
turtle.penup()
turtle.goto(-35, -10)
turtle.pendown()
turtle.goto(-100, 0)
turtle.penup()
turtle.goto(-35, -20)
turtle.pendown()
turtle.goto(-100, -20)
turtle.penup()
turtle.goto(35, 0)
turtle.pendown()
turtle.goto(100, 20)
turtle.penup()
turtle.goto(35, -10)
turtle.pendown()
turtle.goto(100, 0)
turtle.penup()
turtle.goto(35, -20)
turtle.pendown()
turtle.goto(100, -20)
# 隐藏画笔
turtle.hideturtle()
turtle.done()
```
此代码将使用turtle库绘制一个大约在画布中央的卡通猫,头部填充为淡粉色,耳朵,眼睛,鼻子和嘴巴的轮廓都是黑色的,眼睛是白色的,眼珠是黑色的,胡须是黑色的线条。如果您运行上面的代码,将得到下面的输出:
![Kitty Cat](https://i.imgur.com/9GvNzYf.png)
阅读全文