定义函数画正多边形彩图

2+

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','pink','orange','yellow','cyan','green','purple']

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

t = Turtle()
t.pensize(10)

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)





2+

发表评论