用python循环和turtle画出气球
时间: 2023-11-29 20:00:29 浏览: 255
好的,以下是 Python 代码来画出一个气球的图案:
```python
import turtle
# 设置画布和画笔大小
canvas = turtle.Screen()
canvas.setup(width=500, height=500)
pen = turtle.Turtle()
pen.pensize(2)
# 画出气球的线条
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
for i in range(6):
pen.penup()
pen.goto(0, -120 + i*40)
pen.pendown()
pen.color(colors[i])
pen.circle(40)
# 画出气球的细节
pen.penup()
pen.goto(0, -80)
pen.pendown()
pen.color('black')
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(-10, -30)
pen.pendown()
pen.color('black')
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(10, -30)
pen.pendown()
pen.color('black')
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 隐藏画笔并保持画面不关闭
pen.hideturtle()
canvas.mainloop()
```
希望这个代码能够帮助你画出一个漂亮的气球图案!
阅读全文