实例一:
代码语言:javascript复制import turtle
turtle.speed("fastest")
turtle.pensize(1)
color=["red","yellow","blue","green"]
for y in range(250):
turtle.pencolor(color[y%4])
turtle.forward(3*y)
turtle.right(29)
turtle.left(175)
效果图:
实例二
代码语言:javascript复制import turtle
t = turtle.Pen()
t.speed( 0 )
turtle.bgcolor( "black" )
colors = [ "red","orange","yellow","green","blue","purple","pink" ]
sides = int( turtle.numinput( "边数","请输入图形边数,1 到 8 之间:",4,1,8 ) )
your_name = turtle.textinput( "名字","请输入你的名字:" )
for x in range( 0,200):
t.pencolor( colors[x%sides] )
t.penup()
t.forward( x*3/sides x )
t.pendown()
t.write( your_name,font=( "宋体",int( (x 4)/4 ),"bold" ) )
t.left( 360/sides 1 )
t.width( x*sides / 200 )
效果图: