pythonturtle绘制奥运五环
时间: 2023-07-25 11:14:25 浏览: 120
好的,我将为您提供Python代码实现绘制奥运五环。请确保您已经安装了Python的turtle库。
```
import turtle
# 设置画笔的颜色和宽度
turtle.pensize(3)
# 绘制蓝色圆环
turtle.penup() # 抬起画笔,不绘制
turtle.goto(-120, 0) # 移动画笔到指定位置
turtle.pendown() # 放下画笔,开始绘制
turtle.color("blue") # 设置画笔颜色
turtle.circle(40) # 绘制圆形
# 绘制黑色圆环
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.color("black")
turtle.circle(40)
# 绘制红色圆环
turtle.penup()
turtle.goto(120, 0)
turtle.pendown()
turtle.color("red")
turtle.circle(40)
# 绘制绿色圆环
turtle.penup()
turtle.goto(60, -40)
turtle.pendown()
turtle.color("green")
turtle.circle(40)
# 绘制黄色圆环
turtle.penup()
turtle.goto(-60, -40)
turtle.pendown()
turtle.color("yellow")
turtle.circle(40)
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行上面的代码,即可在画布上绘制出奥运五环。效果如下图所示:
![奥运五环](https://cdn.luogu.com.cn/upload/image_hosting/m3m0b1uo.png)
阅读全文