用turtle画奥运五环
时间: 2023-11-04 20:55:52 浏览: 61
Python中使用turtle画奥运五环
5星 · 资源好评率100%
好的,以下是用 Python turtle 库画奥运五环的代码:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
canvas.bgcolor('white')
# 创建五个不同颜色的海龟
blue = turtle.Turtle()
blue.color('blue')
blue.pensize(10)
blue.penup()
blue.goto(-110, -25)
blue.pendown()
yellow = turtle.Turtle()
yellow.color('yellow')
yellow.pensize(10)
yellow.penup()
yellow.goto(-55, -65)
yellow.pendown()
black = turtle.Turtle()
black.color('black')
black.pensize(10)
black.penup()
black.goto(0, -25)
black.pendown()
green = turtle.Turtle()
green.color('green')
green.pensize(10)
green.penup()
green.goto(55, -65)
green.pendown()
red = turtle.Turtle()
red.color('red')
red.pensize(10)
red.penup()
red.goto(110, -25)
red.pendown()
# 画五环
for i in range(5):
blue.circle(50)
yellow.circle(50)
black.circle(50)
green.circle(50)
red.circle(50)
blue.penup()
yellow.penup()
black.penup()
green.penup()
red.penup()
blue.forward(110)
yellow.forward(110)
black.forward(110)
green.forward(110)
red.forward(110)
blue.pendown()
yellow.pendown()
black.pendown()
green.pendown()
red.pendown()
# 隐藏海龟
turtle.hideturtle()
# 保持画布不关闭
turtle.done()
```
运行上述代码后,你会看到一个画着五环图案的窗口。
阅读全文