How Can I Fill These Squares in Turtle - Python

巧了我就是萌 提交于 2019-12-05 18:36:13

I haven't really used turtle, but it look like may this is what you want to do. Correct me if I've assumed the wrong functionality for these calls:

turtle.begin_fill() # Begin the fill process.
turtle.down() # "Pen" down?
for i in range(squares):  # For each edge of the shape
    turtle.forward(40) # Move forward 40 units
    turtle.left(angle) # Turn ready for the next edge
turtle.up() # Pen up
turtle.end_fill() # End fill.

You're drawing a series of triangles, using begin_fill() and end_fill() for each one. What you can probably do is move your calls to begin_fill() and end_fill() outside the inner loop, so you draw a full square and then ask for it to be filled.

Use fill

t.begin_fill()
t.color("red")
for x in range(4):
    t.fd(100)
    t.rt(90)
t.end_fill()

great that you solved it! if you want to make turtle programming easier, use turtle.seth instead of turtle.left or right. turtle.left is relative to the turtle's last position, so you dont have to worry about where the turtle was facing before a command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!