python画小海狸
时间: 2023-11-07 10:04:33 浏览: 176
要在Python中绘制小海狸,您可以使用turtle模块来实现。下面是一个简单的示例代码,可以绘制一个简化的小海狸:
```python
import turtle
# 设置窗口大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("lightblue")
# 绘制身体
turtle.penup()
turtle.goto(-50, -50)
turtle.pendown()
turtle.fillcolor("chocolate")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 绘制头部
turtle.penup()
turtle.goto(-25, 0)
turtle.pendown()
turtle.fillcolor("saddlebrown")
turtle.begin_fill()
turtle.circle(25)
turtle.end_fill()
# 绘制眼睛
turtle.penup()
turtle.goto(-35, 10)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 绘制耳朵
turtle.penup()
turtle.goto(-20, 35)
turtle.pendown()
turtle.fillcolor("saddlebrown")
turtle.begin_fill()
turtle.goto(-40, 55)
turtle.goto(-60, 35)
turtle.goto(-20, 35)
turtle.end_fill()
# 绘制腿
turtle.penup()
turtle.goto(-30, -70)
turtle.pendown()
turtle.pensize(8)
turtle.pencolor("saddlebrown")
turtle.setheading(-45)
turtle.forward(50)
turtle.backward(50)
# 隐藏海龟图标
turtle.hideturtle()
# 点击关闭窗口退出程序
turtle.exitonclick()
```
这段代码使用了Python的 turtle 模块来绘制小海狸的身体、头部、眼睛、耳朵和腿部。可以根据需要进行修改和扩展。运行代码后,会弹出一个窗口显示绘制的小海狸。