python中利用turtle绘制奥运五环。颜色:blue, yellow, black, green, red。
时间: 2024-02-19 15:59:43 浏览: 82
好的,下面是绘制奥运五环的 Python 代码:
```python
import turtle
# 画布大小
turtle.setup(800, 600)
# 画笔大小
turtle.pensize(6)
# 蓝色圆环
turtle.pencolor("blue")
turtle.penup()
turtle.goto(-110, -50)
turtle.pendown()
turtle.circle(50)
# 黄色圆环
turtle.pencolor("yellow")
turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.circle(50)
# 黑色圆环
turtle.pencolor("black")
turtle.penup()
turtle.goto(110, -50)
turtle.pendown()
turtle.circle(50)
# 绿色圆环
turtle.pencolor("green")
turtle.penup()
turtle.goto(-55, -100)
turtle.pendown()
turtle.circle(50)
# 红色圆环
turtle.pencolor("red")
turtle.penup()
turtle.goto(55, -100)
turtle.pendown()
turtle.circle(50)
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.done()
```
运行以上代码后,将会在画布上绘制出奥运五环的图形。
阅读全文