彩色螺旋线
import turtle
length=int(input('最长线段的长度:'))
direction=int(input('请输入方向值(1:左旋,2:右旋):'))
color=input('请输入颜色英文(red,yellow,blue,black,gold,purple,brown,pink,seashell,tomato,while,magenta,cyan):')
turtle.pencolor(color)
turtle.width(2)
while length>0 :
turtle.forward(length)
turtle.back(length)
if direction==1:
turtle.left(5)
else:
turtle.right(5)
length=length-5
运行结果
最长线段的长度:300
请输入方向值(1:左旋,2:右旋):2
请输入颜色英文(red,yellow,blue,black,gold,purple,brown,pink,seashell,tomato,while,magenta,cyan):pink
填充色和描边色
import turtle
n=int(input("请输入边数:"))
turtle.penup()
turtle.goto(-200,200)
turtle.pendown()
turtle.width(5)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for i in range(1,n+1):
turtle.forward(100)
turtle.right(360/n)
turtle.end_fill()
turtle.hideturtle()
turtle.done()
运行结果