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()
如何使用Python turtle画花
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/77916fdbb4c5edfa09093a42112a6dce.html