turtle库描绘彩虹旋转图

turtule库描绘彩虹旋转图

彩虹旋转图

运用turtle库编写彩虹旋转图,由于未限定运行时间,此程序需手动关闭,否则将持续运行。(后续如有空将会对其设定运行时间。)

代码如下

import turtle
q =turtle.Pen()
turtle.bgcolor("black")
sides = 7
colors =["red","orange","yellow","green","cyan","blue","purple"]
for x in range(360):
    q.pencolor(colors[x%sides])
    q.forward(x*3/sides+x)
    q.left(360/sides+1)
    q.width(x*sides/200)

运行之后效果

turtle库描绘彩虹旋转图_第1张图片

你可能感兴趣的:(turtle库描绘彩虹旋转图)