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

多线程海龟移动动画例子_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))

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客

评论已关闭。