请用Python画一只猫。
时间: 2023-05-22 17:06:11 浏览: 291
源码用python的tkinter模块的Canvas画哆啦a梦
5星 · 资源好评率100%
好的,以下是使用 Python 制作一只猫的代码:
```python
import turtle
# 绘制猫头
def draw_head():
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 绘制猫身
def draw_body():
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(70)
turtle.end_fill()
# 绘制猫耳朵
def draw_ears():
turtle.penup()
turtle.goto(-25, 150)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(25, 150)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制猫眼
def draw_eyes():
turtle.penup()
turtle.goto(-15, 120)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(15, 120)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制猫嘴
def draw_mouth():
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.goto(0, 80)
# 绘制猫腿
def draw_legs():
turtle.penup()
turtle.goto(-35, 0)
turtle.pendown()
turtle.goto(-50, -50)
turtle.goto(-35, -100)
turtle.penup()
turtle.goto(35, 0)
turtle.pendown()
turtle.goto(50, -50)
turtle.goto(35, -100)
# 绘制猫尾巴
def draw_tail():
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.right(30)
turtle.circle(70, 60)
if __name__ == '__main__':
turtle.speed(1)
draw_head()
draw_body()
draw_ears()
draw_eyes()
draw_mouth()
draw_legs()
draw_tail()
turtle.done()
```
这里使用 `turtle` 模块来进行绘图,运行代码后会弹出一个窗口显示绘制出来的猫。
阅读全文