python代码画小狗
时间: 2023-11-12 20:57:23 浏览: 140
好的,以下是使用turtle库绘制小狗的Python代码:
```python
import turtle
# 绘制狗头
def draw_head():
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.circle(50)
turtle.penup()
turtle.goto(20, 120)
turtle.pendown()
turtle.dot(10)
turtle.penup()
turtle.goto(-20, 120)
turtle.pendown()
turtle.dot(10)
# 绘制狗身
def draw_body():
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.circle(30)
turtle.penup()
turtle.goto(0, 20)
turtle.pendown()
turtle.circle(40)
# 绘制狗腿
def draw_legs():
turtle.penup()
turtle.goto(-30, 0)
turtle.pendown()
turtle.right(45)
turtle.forward(60)
turtle.penup()
turtle.goto(30, 0)
turtle.pendown()
turtle.left(90)
turtle.forward(60)
# 绘制狗尾巴
def draw_tail():
turtle.penup()
turtle.goto(40, -10)
turtle.pendown()
turtle.right(45)
turtle.circle(20, 180)
# 绘制小狗
def draw_dog():
draw_head()
draw_body()
draw_legs()
draw_tail()
# 设置画布和画笔
turtle.setup(500, 500)
turtle.pensize(5)
# 绘制小狗
draw_dog()
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
阅读全文