【发布时间】:2020-09-17 22:06:48
【问题描述】:
我只是想知道如何在六边形的每一行上获得不同的颜色。下面我有所需的输出和输入。
立即输出 - Link to output right now
我想要的输出 - Link to output I want
import turtle as trtl
colors = ["#9c2921", "#cf8e04","#f5d905",]
#--------------------
num_sides = int(input("Enter the number of sides(Enter 6 to get the output of the real image): "))
if num_sides == 6:
print("Desired artwork is displayed")
side_length = 25
circumradius = side_length
angle = 360/len(colors)
trtl.width(10)
for color in colors:
trtl.color(color)
trtl.pensize(10)
for move_turtle in range(1):
trtl.penup()
trtl.sety(-circumradius)
trtl.pendown()
trtl.circle(circumradius, steps = num_sides)
circumradius *= 2
trtl.hideturtle()
【问题讨论】:
-
您在一次调用中绘制形状,因此它只能是一种颜色。对于单独的颜色,您需要分别绘制每一侧。
-
这个问题与您也问过的this 非常相似。如果您最终再次访问 Stack Overflow,我会推荐 accepting cdlane's solution below。
标签: python python-3.x turtle-graphics python-turtle