Python Turtle绘制漂亮彩色螺旋线及一闪而过的解决
该算法用于Python Turtle实现画出漂亮的彩色螺旋线,具体如下,注意代码的缩进情况:
#彩色螺旋线
import turtle
import time
turtle.pensize(2)
turtle.bgcolor("black")
colors = ["red", "yellow",'purple','blue']
turtle.tracer(False)
for x in range(400):
turtle.forward(2*x)
turtle.color(colors[x % 4])
turtle.left(91)
turtle.tracer(True)
在用Sublime Text 3.2调用Turtle画图时,运行上面的代码显示彩色螺旋线画面一闪而过。
最后加上一句turtle.done()即可解决
#彩色螺旋线
import turtle
turtle.pensize(2)
turtle.bgcolor("black")
colors = ["red","yellow","purple","blue"]
turtle.tracer(False)
for x in range(400):
turtle.forward(2*x)
turtle.color(colors[x % 4])
turtle.left(91)
turtle.tracer(True)
turtle.done()
效果如下: