填充颜色不适用于我的函数(Python海龟图形)
填充颜色不适用于我的函数(Python海龟图形),python,turtle-graphics,Python,Turtle Graphics,fillcolor()在这个函数中根本不起作用——我不明白为什么。它适用于我的所有其他功能: from turtle import Turtle from random import randint t = Turtle() def rocks(): for i in range(5): t.penup() t.goto(randint(-300,0), randint(-200,0)) for x in range(40):
fillcolor()
在这个函数中根本不起作用——我不明白为什么。它适用于我的所有其他功能:
from turtle import Turtle
from random import randint
t = Turtle()
def rocks():
for i in range(5):
t.penup()
t.goto(randint(-300,0), randint(-200,0))
for x in range(40):
t.pendown()
t.fillcolor("gray")
t.fillcolor()
t.begin_fill()
t.forward(5)
t.left(25)
t.right(27)
t.forward(5)
t.right(20)
t.end_fill()
t.speed("fastest")
rocks()
问题是循环中有
begin\u fill()
&end\u fill()
,这意味着他们试图填充短线段。您需要在循环周围使用它们来填充整个形状:
from turtle import Turtle, Screen
from random import randint
def rocks(t):
t.fillcolor('gray')
for _ in range(5):
t.penup()
t.goto(randint(-300, 0), randint(-200, 0))
t.begin_fill()
for _ in range(15):
t.pendown()
t.forward(5)
t.right(2)
t.forward(5)
t.right(22)
t.end_fill()
screen = Screen()
turtle = Turtle()
turtle.speed('fastest')
rocks(turtle)
turtle.hideturtle()
screen.exitonclick()