加入收藏 | 设为首页 | 会员中心 | 我要投稿 牡丹江站长网 (https://www.0453zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Python Turtle绘制漂亮彩色螺旋线及一闪而过的处理

发布时间:2021-12-05 12:42:03 所属栏目:教程 来源:互联网
导读:该算法用于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): turtl
该算法用于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()

(编辑:牡丹江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!