利用turtle库绘制小动物
时间: 2023-10-02 10:04:25 浏览: 88
好的,我可以为您提供一个简单的示例来利用turtle库绘制小动物。以下是一个绘制小狗的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(400, 400)
turtle.bgcolor('white')
# 画小狗的头
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.setheading(60)
turtle.circle(80, 120)
# 画小狗的身体
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.setheading(-120)
turtle.circle(80, 120)
# 画小狗的腿
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.setheading(-30)
turtle.forward(60)
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.setheading(-150)
turtle.forward(60)
# 画小狗的尾巴
turtle.penup()
turtle.goto(30, 30)
turtle.pendown()
turtle.setheading(60)
turtle.circle(30, 120)
# 画小狗的眼睛
turtle.penup()
turtle.goto(-20, 120)
turtle.pendown()
turtle.setheading(0)
turtle.circle(20)
turtle.penup()
turtle.goto(-20, 130)
turtle.pendown()
turtle.dot(10)
turtle.penup()
turtle.goto(20, 120)
turtle.pendown()
turtle.setheading(0)
turtle.circle(20)
turtle.penup()
turtle.goto(20, 130)
turtle.pendown()
turtle.dot(10)
# 画小狗的鼻子
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.dot(20)
# 完成绘制
turtle.done()
```
您可以运行这段代码,查看绘制的小狗效果。
阅读全文