用turtle画一只小狗
时间: 2023-11-04 15:55:50 浏览: 158
好的,以下是使用Python的turtle库来绘制一只小狗的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 600)
turtle.bgcolor("#FBEFFB")
# 绘制狗的头部
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(50)
turtle.end_fill()
# 绘制狗的眼睛
turtle.penup()
turtle.goto(-30, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color("#FFFFFF")
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color("#000000")
turtle.circle(5)
turtle.end_fill()
# 绘制狗的耳朵
turtle.penup()
turtle.goto(-80, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(20, 90)
turtle.goto(-80, 110)
turtle.end_fill()
turtle.penup()
turtle.goto(-80, 110)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(10, 90)
turtle.goto(-70, 100)
turtle.end_fill()
# 绘制狗的身体
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(100)
turtle.end_fill()
# 绘制狗的腿
turtle.penup()
turtle.goto(-70, -70)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(20, 90)
turtle.goto(-70, -100)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, -100)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(10, 90)
turtle.goto(-60, -110)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -70)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(20, -90)
turtle.goto(70, -100)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -100)
turtle.pendown()
turtle.begin_fill()
turtle.color("#A52A2A")
turtle.circle(10, -90)
turtle.goto(60, -110)
turtle.end_fill()
# 绘制狗的尾巴
turtle.penup()
turtle.goto(80, 50)
turtle.pendown()
turtle.color("#A52A2A")
turtle.pensize(10)
turtle.right(45)
turtle.forward(50)
turtle.right(45)
turtle.forward(50)
turtle.right(135)
turtle.forward(80)
turtle.done()
```
绘制完成后,可以得到以下小狗的图像:
![小狗](https://i.imgur.com/9f7LGuI.png)
阅读全文