用python画一个兔子
时间: 2023-05-19 14:07:32 浏览: 289
可以使用Python的turtle库来画一个兔子,以下是示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('white')
# 画兔子的头部
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.circle(50)
# 画兔子的耳朵
turtle.penup()
turtle.goto(-70, 170)
turtle.pendown()
turtle.setheading(60)
turtle.circle(-30, 120)
turtle.setheading(0)
turtle.circle(-30, 120)
# 画兔子的眼睛
turtle.penup()
turtle.goto(-80, 130)
turtle.pendown()
turtle.dot(20, 'black')
turtle.penup()
turtle.goto(-60, 130)
turtle.pendown()
turtle.dot(20, 'black')
# 画兔子的嘴巴
turtle.penup()
turtle.goto(-80, 110)
turtle.pendown()
turtle.setheading(-30)
turtle.circle(30, 60)
turtle.setheading(0)
# 画兔子的身体
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(0)
turtle.circle(100)
# 画兔子的前腿
turtle.penup()
turtle.goto(-50, -100)
turtle.pendown()
turtle.setheading(60)
turtle.circle(-30, 120)
turtle.setheading(0)
turtle.circle(-30, 120)
# 画兔子的后腿
turtle.penup()
turtle.goto(50, -100)
turtle.pendown()
turtle.setheading(120)
turtle.circle(30, 120)
turtle.setheading(180)
turtle.circle(30, 120)
# 完成画图
turtle.done()
```
运行以上代码,即可在画布上看到一个可爱的兔子。
阅读全文