python用turtle画熊大
时间: 2024-06-04 12:04:49 浏览: 203
菊花绘制_python编程_python_turtle绘图_
5星 · 资源好评率100%
Python中的turtle库是一个非常有趣的库,它可以让你用编程的方式来绘制各种形状,包括熊大。你可以通过一系列指令来控制小海龟的移动和绘图。
以下是一个示例代码,可以用turtle库来绘制一个简单的熊大:
```python
import turtle
# 设置画布的大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("white")
# 画头部
turtle.pensize(3)
turtle.color("black")
turtle.circle(100)
# 画眼睛
turtle.penup()
turtle.goto(-50, 150)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, 150)
turtle.pendown()
turtle.color("black")
turtle.circle(30)
# 画鼻子
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color("pink")
turtle.circle(20)
turtle.end_fill()
# 画嘴巴
turtle.penup()
turtle.goto(-80, 50)
turtle.pendown()
turtle.right(45)
turtle.forward(80)
turtle.right(90)
turtle.forward(60)
# 画身体
turtle.penup()
turtle.goto(-150, -100)
turtle.pendown()
turtle.begin_fill()
turtle.color("brown")
turtle.forward(300)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(300)
turtle.right(90)
turtle.forward(200)
turtle.end_fill()
# 画左手
turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()
turtle.begin_fill()
turtle.color("brown")
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 画右手
turtle.penup()
turtle.goto(100, -100)
turtle.pendown()
turtle.begin_fill()
turtle.color("brown")
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 画左脚
turtle.penup()
turtle.goto(-150, -300)
turtle.pendown()
turtle.begin_fill()
turtle.color("brown")
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 画右脚
turtle.penup()
turtle.goto(50, -300)
turtle.pendown()
turtle.begin_fill()
turtle.color("brown")
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 隐藏小海龟并保存绘图结果
turtle.hideturtle()
ts = turtle.getscreen()
ts.getcanvas().postscript(file="bear.eps")
# 显示绘图结果
ts.mainloop()
```
阅读全文