多线程海龟移动动画例子_multithread turtle example

"""
   多线程海龟移动动画例子_multithread turtle example 
"""
from queue import Queue
from random import randint
from turtle import Screen, Turtle
from threading import Thread, active_count

QUEUE_SIZE = 1
turtle_SPEED = 3

def move_turtle(turtle, direction):
    """
       移动海龟线程,超过x坐标288就往下移50
    """
    x, y = turtle.position()

    while True:
        while direction == "right":

            if x > 288:
                y -= 50
                actions.put((turtle.sety, y))
                direction = "left"
            else:
                x += turtle_SPEED
                actions.put((turtle.setx, x))

        while direction == "left":
            if x < -288:
                y -= 50
                actions.put((turtle.sety, y))
                direction = "right"
            else:
                x -= turtle_SPEED
                actions.put((turtle.setx, x))

You must log in to read the rest of this article. Please log in or register as a user.