[英]turtle triangles, and user input. python 3
我試圖讓它在詢問用戶顏色后畫一個三角形的圓。 三角形很好,但填充黑色。 我懷疑錯誤在底部附近的“ for i in range”部分中。
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)
調用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()
請注意,在fillcolor()
的文檔中 ,如果不帶參數調用它,則它實際上會返回當前的填充顏色。 在這種情況下,不是您想要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.