用Python画一个小猫
时间: 2023-11-16 08:49:03 浏览: 328
python+pygame简单画板实现代码实例
当然可以!以下是用Python绘制一个小猫的示例代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
# 绘制小猫的头部
pen.color("black")
pen.fillcolor("yellow")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 绘制小猫的左眼
pen.penup()
pen.goto(-15, 60)
pen.pendown()
pen.color("black")
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 绘制小猫的右眼
pen.penup()
pen.goto(15, 60)
pen.pendown()
pen.color("black")
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 绘制小猫的鼻子
pen.penup()
pen.goto(0, 40)
pen.pendown()
pen.color("black")
pen.fillcolor("red")
pen.begin_fill()
pen.circle(5)
pen.end_fill()
# 绘制小猫的嘴巴
pen.penup()
pen.goto(-25, 20)
pen.pendown()
pen.color("black")
pen.right(90)
pen.circle(25, 180)
# 绘制小猫的胡须
pen.penup()
pen.goto(-30, 45)
pen.pendown()
pen.color("black")
pen.seth(-60)
for i in range(3):
pen.forward(15)
pen.backward(15)
pen.right(30)
# 隐藏画笔
pen.hideturtle()
# 结束绘制
turtle.done()
```
运行这段代码,你将看到一个可爱的小猫在画布上出现!希望你喜欢!
阅读全文