用turtle绘制奥运五环
时间: 2023-11-19 08:05:35 浏览: 63
Python中使用turtle画奥运五环
5星 · 资源好评率100%
好的,我可以为您展示使用Python的turtle库绘制奥运五环的代码。
```python
import turtle
# 创建一个画布
canvas = turtle.Screen()
canvas.title("奥运五环")
# 创建一个小乌龟
pen = turtle.Turtle()
# 设置画笔颜色和宽度
pen.pensize(10)
pen.color("blue")
# 绘制蓝色环
pen.penup()
pen.goto(-110, -25)
pen.pendown()
pen.circle(50)
# 设置画笔颜色
pen.color("black")
# 绘制黑色环
pen.penup()
pen.goto(0, -25)
pen.pendown()
pen.circle(50)
# 设置画笔颜色
pen.color("red")
# 绘制红色环
pen.penup()
pen.goto(110, -25)
pen.pendown()
pen.circle(50)
# 设置画笔颜色
pen.color("yellow")
# 绘制黄色环
pen.penup()
pen.goto(-55, -75)
pen.pendown()
pen.circle(50)
# 设置画笔颜色
pen.color("green")
# 绘制绿色环
pen.penup()
pen.goto(55, -75)
pen.pendown()
pen.circle(50)
# 隐藏小乌龟
pen.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行这段代码,将会得到如下的结果:
![五环](https://img-blog.csdn.net/20180624212249479?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hpdGdyZXkxMTIz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)
阅读全文