利用turtle库绘制四个圆形螺旋,颜色为红、绿、蓝、黄
时间: 2023-07-10 22:09:57 浏览: 142
好的,以下是利用turtle库绘制四个圆形螺旋的代码,颜色为红、绿、蓝、黄:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔颜色和画布背景色
pen.width(3)
canvas.bgcolor("black")
# 绘制红色圆形螺旋
pen.penup()
pen.goto(-200, 0)
pen.pendown()
pen.pencolor("red")
for i in range(100):
pen.circle(5*i)
pen.left(10)
# 绘制绿色圆形螺旋
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.pencolor("green")
for i in range(100):
pen.circle(5*i)
pen.left(10)
# 绘制蓝色圆形螺旋
pen.penup()
pen.goto(200, 0)
pen.pendown()
pen.pencolor("blue")
for i in range(100):
pen.circle(5*i)
pen.left(10)
# 绘制黄色圆形螺旋
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.pencolor("yellow")
for i in range(100):
pen.circle(5*i)
pen.left(10)
# 隐藏画笔
pen.hideturtle()
# 显示画布
canvas.mainloop()
```
运行上述代码,即可在画布上看到绘制出的四个圆形螺旋,颜色分别为红、绿、蓝、黄。
阅读全文