用turtle库画一个小狗
时间: 2024-05-06 17:21:50 浏览: 134
好的,我可以使用Python中的turtle库来为你画一个小狗。以下是代码:
```python
import turtle
# 创建画布并初始化画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
pen.speed(0)
pen.penup()
pen.goto(0, -150)
pen.pendown()
# 画狗头
pen.fillcolor("brown")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画眼睛
pen.penup()
pen.goto(-40, 40)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(40, 40)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画耳朵
pen.penup()
pen.goto(-80, 160)
pen.pendown()
pen.fillcolor("brown")
pen.begin_fill()
pen.right(45)
pen.forward(60)
pen.right(45)
pen.forward(40)
pen.right(90)
pen.forward(40)
pen.right(45)
pen.forward(60)
pen.right(45)
pen.end_fill()
pen.penup()
pen.goto(80, 160)
pen.pendown()
pen.fillcolor("brown")
pen.begin_fill()
pen.left(45)
pen.forward(60)
pen.left(45)
pen.forward(40)
pen.left(90)
pen.forward(40)
pen.left(45)
pen.forward(60)
pen.left(45)
pen.end_fill()
# 画鼻子
pen.penup()
pen.goto(0, 20)
pen.pendown()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(30)
pen.end_fill()
# 画口部
pen.penup()
pen.goto(0, -40)
pen.pendown()
pen.right(90)
pen.circle(40, 180)
# 完成绘画
pen.hideturtle()
canvas.exitonclick()
```
你可以将这些代码复制到Python解释器中并运行它们,即可在屏幕上看到一个可爱的小狗了。
阅读全文