用python turtle画兔子
时间: 2024-01-10 20:04:55 浏览: 183
python用turtle画画
以下是使用Python的turtle库绘制兔子的示例代码:
```python
import turtle
# 创建一个画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔的形状和颜色
pen.shape("turtle")
pen.color("brown")
# 绘制兔子的头部
pen.circle(50)
# 绘制兔子的耳朵
pen.setheading(60)
pen.circle(30, 180)
pen.setheading(-60)
pen.circle(30, 180)
# 绘制兔子的眼睛
pen.penup()
pen.goto(-20, 60)
pen.pendown()
pen.dot(10)
pen.penup()
pen.goto(20, 60)
pen.pendown()
pen.dot(10)
# 绘制兔子的嘴巴
pen.penup()
pen.goto(-25, 40)
pen.pendown()
pen.setheading(-60)
pen.circle(25, 120)
# 绘制兔子的身体
pen.penup()
pen.goto(0, -50)
pen.pendown()
pen.setheading(0)
pen.circle(80)
# 绘制兔子的四条腿
pen.penup()
pen.goto(-40, -130)
pen.pendown()
pen.setheading(-45)
pen.forward(60)
pen.penup()
pen.goto(40, -130)
pen.pendown()
pen.setheading(-135)
pen.forward(60)
pen.penup()
pen.goto(-40, -150)
pen.pendown()
pen.setheading(-135)
pen.forward(60)
pen.penup()
pen.goto(40, -150)
pen.pendown()
pen.setheading(-45)
pen.forward(60)
# 绘制兔子的尾巴
pen.penup()
pen.goto(0, -150)
pen.pendown()
pen.setheading(0)
pen.circle(15, 180)
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
```
阅读全文