龟三角形和用户输入。蟒蛇3

时间:2015-10-18 03:57:30

标签: python python-3.x input turtle-graphics

我想在用户询问颜色后绘制一个三角形圆圈。三角形出来很好,但填充黑色。我怀疑错误是在"中的某个地方"底部附近。

import turtle
def draw_triangle(side_length):#triangle def
    for x in range (3):
        turtle. left(120)
        turtle. forward(side_length)                   
    return None

def jump(distance):#jump definition
    turtle. penup()
    turtle. forward(distance)
    turtle. pendown()
    return None

def color_triangle(side_length, color):#makes the triangle color filled
    turtle. fillcolor()
    turtle. begin_fill()
    draw_triangle(size)
    turtle. end_fill()
    return None
color_a= input("choose a color for the first triangle ")
color_b= input ("choose a color for the second triangle ")
color_c= input("choose a color for the third triangle ")
back_color= input ("choose a color for the backround ")


my_colors= []

if color_a not in my_colors:
    my_colors . append (color_a)
if color_b not in my_colors:
    my_colors . append (color_b)
if color_c not in my_colors:
    my_colors . append (color_c)
color_number = 0
size= 75
move= 80
for i in range(10):
    the_color = my_colors[color_number]
    color_triangle(size, the_color)
    color_number= color_number +1
    if color_number >= len(my_colors):
        color_number=0
    jump(move)
    turtle. left (35)
turtle.bgcolor (back_color)

1 个答案:

答案 0 :(得分:0)

致电turtle.fillcolor()

时,您并非使用颜色

color_triangle功能更新为:

def color_triangle(side_length, color):
    turtle.fillcolor(color)  # See here! Actually set the fill color!
    turtle.begin_fill()
    draw_triangle(size)
    turtle.end_fill()

注意documentation for fillcolor()如果你不带参数调用它,它实际上会返回当前的填充颜色。在这种情况下,不是你想要的。