python turtle画热气球
时间: 2024-01-04 18:20:11 浏览: 138
以下是使用Python Turtle库绘制热气球的示例代码:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
pen.speed(2)
# 绘制热气球
def draw_balloon():
# 绘制气球的线
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.color("red")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 绘制气球的篮子
pen.penup()
pen.goto(-20, -300)
pen.pendown()
pen.color("brown")
pen.begin_fill()
pen.forward(40)
pen.left(90)
pen.forward(100)
pen.left(90)
pen.forward(40)
pen.left(90)
pen.forward(100)
pen.end_fill()
# 绘制气球的绳子
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.color("black")
pen.width(5)
pen.right(90)
pen.forward(150)
# 调用函数绘制热气球
draw_balloon()
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
```
阅读全文