定义函数画正方形彩图

1+


from turtle import Turtle,Screen

def draw_polygon(haigui,n,length,k):
    """画正n边形函数
       haigui:海龟
       n:边数
       length:边长
       k:方向参数
    """
    for x in range(n):
        haigui.fd(length)
        haigui.left(k*360/n)

cs=['red','yellow','cyan','green','purple','pink','orange']

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

t = Turtle()
t.pensize(10)
t.speed(0)

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)




1+

发表评论