定义函数画正多边形彩图

0

from turtle import Turtle,Screen

cs=['red','blue','brown','black','cyan','pink','purple','orange']

screen = Screen()
screen.delay(0)
screen.bgcolor('black')

def draw_polygon(turtle,n,length,k):
    for x in range(n):
        turtle.fd(length)
        turtle.lt(k*360/n)
        turtle.speed(0)
        

t = Turtle()
t.pensize(20)

for n in range(3,10):
    t.pencolor(cs[n-3])
    draw_polygon(t,n,100,1)

for n in range(3,10):
    t.pencolor(cs[n-3])
    draw_polygon(t,n,100,-1)
0

发表评论