连续画正多边形while循环示例

"""
   连续画正多边形.py
"""

from turtle import *

colors = ['red','orange','yellow','green','cyan',          
          'blue','purple','brown','pink','magenta']
t = Turtle()

screen = t.getscreen()
screen.delay(0)
screen.title("连续画正多边形")

t.width(4)
for i in range(18):
    
    n = 3
    while n < 12 :
        index = n % len(colors)    # 通过求余设定索引
        ys = colors[index]         # 取颜色
        t.color(ys)                # 设定颜色
        
        c = 0
        while c < n :
            t.fd(10)
            t.right(360/n)
            c = c + 1
            
        t.fd(10+n*3)
        n = n + 1

    t.goto(0,0)         # 回到屏幕中央
    t.right(20)
    

连续画正多边形while海龟画图示例