帮别人做一个Python原创作品的副作品,一个像风火轮一样的图形?

帮别人做一个Python原创作品的副作品,一个像风火轮一样的图形?



以下是这个图案的代码,画完后,它会旋转:

import turtle

def draw_polygon(n,length,fc,heading):
    """n:边数,length:边长,fc:填充颜色,heading是1或者负一"""
    turtle.fillcolor(fc)
    turtle.begin_fill()
    for i in range(n):
        turtle.fd(length)
        turtle.left(heading * 360/n)
    turtle.end_fill()

n = 6
length = 20
turtle.speed(0)
turtle.delay(0)
turtle.bgcolor('black')
turtle.penup()
turtle.sety(-2*length)
turtle.left(30)
turtle.fillcolor('#FE9007')
turtle.pendown()
turtle.begin_poly()
turtle.begin_fill()
for i in range(2*n):
    if i%2==1:
        turtle.fd(length)
        turtle.fd(length)
        turtle.left(360/n)
    else:
        for j in range(3):
            turtle.fd(length)
            turtle.right(60)
        turtle.left(90)
        draw_polygon(3,length,'',1)
        turtle.right(60)
        draw_polygon(4,length,'red',-1)
        turtle.right(90)
        for j in range(2):
            turtle.fd(length)
            turtle.right(60)         
turtle.end_fill()
turtle.end_poly()
turtle.speed(0)
turtle.delay(0)
turtle.sety(-length)
poly = turtle.get_poly()
turtle.addshape('p',poly)
turtle.clear()
turtle.shape('p')
while True:turtle.left(0.1)
    

李兴球

李兴球的博客是Python创意编程原创博客