The method of filling turtles works on shapes, that is, a completely limited area. Therefore, instead of drawing a grid, you need to think about how to draw a series of squares.
, . , .
def draw_filled_square(this_turtle, size):
"""Draw a square by drawing a line and turning through 90 degrees 4 times"""
this_turtle.pendown()
this_turtle.fill(True)
for _ in range(4):
this_turtle.forward(size)
this_turtle.right(90)
this_turtle.fill(False)
this_turtle.penup()
:
window = turtle.Screen()
myturtle = turtle.Turtle()
square_size = 90
myturtle.goto(-300, 200)
draw__filled_square(myturtle, square_size)
. , , , .
, , , , . .
- , this_turtle.fill(False) .
- (1,2,3,4,1,2,3,4...), modulo (). Modulo , , x y 0, , x y. x% y == 0:
- :
def drum_loop(x):
if x % 4 == 0:
print("bang!")
else:
print("tish")
for i in range(1,9):
drum_loop(i)
, 0, 1, 0, 1.
, :
for i in range(8):
if i % 2 == 0:
draw_filled_square(myturtle, square_size)
else:
draw_unfilled_square(myturtle, square_size)
# move to start of next square
myturtle.forward(square_size)
, , modulo 2 .
, , , . ( , ).