Create More Than Two Turtles And Moving Them
How to make few turtles in a screen and make them move one at once?
Solution 1:
You can use turtle.Turtle()
to create many turtles and then you can use it one by one to make small move. Turtles will move almost at the same time.
import turtle
t1 = turtle.Turtle()
t2 = turtle.Turtle()
for x in range(36):
# first turtle makes small move
t1.left(10)
t1.forward(10)
# second turtle makes small move
t2.right(10)
t2.forward(10)
turtle.done()
If you want to move all the time (and do other things at the same time)
then you can use ontimer()
to make small moves.
import turtle
defmove_t1():
# first turtle makes small move
t1.left(10)
t1.forward(10)
# repeat after 100ms
turtle.ontimer(move_t1, 100)
defmove_t2():
# second turtle makes small move
t2.right(10)
t2.forward(10)
# repeat after 100ms
turtle.ontimer(move_t2, 100)
t1 = turtle.Turtle()
t2 = turtle.Turtle()
move_t1() # first turtle makes first move
move_t2() # second turtle makes first move
turtle.done()
Post a Comment for "Create More Than Two Turtles And Moving Them"