Pythonのカメ塗装の花を使用する方法

Pythonのカメ塗装の花を使用する方法

コードは以下の通りであります:

from turtle import Turtle, Screen
import math

COLORS = ["red", "yellow", "blue", "brown", "pink", "green", "black", "orange", "purple"]

def draw_polygons(sides, area):
    """ Draws a polygon with 'sides' sides and area 'area' """

    for i, sd in enumerate(range(sides, 2, -1)):
        side_length = math.sqrt(area / sd * 4 * math.atan(math.pi / sd))
        # print("side length =", side_length)

        a_color = COLORS[i % len(COLORS)]
        rest.fillcolor(a_color)

        rest.pendown()
        rest.begin_fill()

        for _ in range(sd):
            rest.forward(side_length)
            rest.left(360 / sd)

        rest.end_fill()
        rest.penup()

        rest.forward(side_length / 2)
        rest.right(30)

wn = Screen()

rest = Turtle()
rest.speed('fastest')

draw_polygons(20, 40_000)

rest.hideturtle()

wn.exitonclick()

おすすめ

転載: www.linuxidc.com/Linux/2020-01/162131.htm