用python的turtle画一只猫
时间: 2023-10-19 13:05:39 浏览: 191
好的,以下是用 Python 的 turtle 模块画一只猫的代码:
```python
import turtle
# 设置画笔
pen = turtle.Turtle()
pen.pensize(5)
pen.speed(10)
# 画猫脸
pen.fillcolor('#F5B041')
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画猫鼻子
pen.penup()
pen.goto(0, 30)
pen.pendown()
pen.fillcolor('#F7DC6F')
pen.begin_fill()
pen.circle(25)
pen.end_fill()
# 画猫眼睛
pen.penup()
pen.goto(-40, 80)
pen.pendown()
pen.fillcolor('white')
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.fillcolor('black')
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(40, 80)
pen.pendown()
pen.fillcolor('white')
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.fillcolor('black')
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画猫嘴巴
pen.penup()
pen.goto(-60, 10)
pen.pendown()
pen.right(45)
pen.circle(50, 90)
# 画猫胡须
pen.penup()
pen.goto(-20, 60)
pen.pendown()
pen.right(30)
for i in range(3):
pen.forward(30)
pen.backward(30)
pen.left(15)
pen.right(75)
for i in range(3):
pen.forward(30)
pen.backward(30)
pen.right(15)
# 隐藏画笔
pen.hideturtle()
# 保持窗口不关闭
turtle.done()
```
运行代码,即可在窗口中看到一只可爱的猫咪!
阅读全文