python3D多彩重力弹球

"""3D多彩重力弹球,这是用Python的海龟画图制作的3D多彩重力弹球。
在程序中新建了Ball类,它继承自Turtle,由于它不需要画画,所以它在初始化的时候就让它抬笔penup。
给Ball设计了xspeed和yspeed属性,这代表每次移动的水平和垂直位移。由于是重力弹球,所以设计了加速度属性。
"""
from turtle import *
from random import randint,choice
from time import sleep
    
class Ball(Turtle):
    def __init__(self,color,size,height):
        Turtle.__init__(self,visible=False,shape='blank')       
        self.penup()                        # 抬笔
        self.xspeed = 0                     # 单位水平位移
        self.yspeed = 0                     # 垂直水平位移
        imagefile = color + "_balls/ball-" + str(size) + ".gif"
        self.shape(imagefile)               # 设定形状
        self.setx(randint(50-self.screen.window_width()//2,self.screen.window_width()//2-50))
        self.sety(height)
        self.accspeed = -0.5 
        self.showturtle()        
        
    def move(self):        
        """移动弹球""" 
        self.setx(self.xcor() + self.xspeed)
        self.sety(self.ycor() + self.yspeed)
        
        if self.ycor() < -300:
            self.sety(-300)
            self.yspeed = -self.yspeed * 0.9  # 阻力系数                 
            if abs(self.yspeed) < 5: return   # 小于这个数停止
             
        else:
            self.yspeed = self.yspeed + self.accspeed            
        #self.screen.cv.update()
        self.screen.ontimer(self.move,10)

if __name__ == "__main__":

    colors = ["cyan",'yellow','green','pink','purple']
    size = list(range(10,101,10))

    yellow_balls = ["yellow_balls/ball-" + str(i) + ".gif" for i in size]
    cyan_balls = ["cyan_balls/ball-" + str(i) + ".gif" for i in size]
    green_balls = ["green_balls/ball-" + str(i) + ".gif" for i in size]
    pink_balls = ["pink_balls/ball-" + str(i) + ".gif" for i in size]
    purple_balls = ["purple_balls/ball-" + str(i) + ".gif" for i in size]
     
    screen = Screen()
    screen.title("3D多彩重力弹球,作者:李兴球")
    screen.delay(0)
    screen.bgcolor("black")
    # screen.bgpic("bg3d.png")
    [screen.addshape(image) for image in yellow_balls]
    [screen.addshape(image) for image in cyan_balls]
    [screen.addshape(image) for image in green_balls]
    [screen.addshape(image) for image in pink_balls]
    [screen.addshape(image) for image in purple_balls]    

    heights = list(range(50,301,50))
    balls= [Ball(choice(colors),choice(size),choice(heights)) for i in range(10)]
    screen.update()
    sleep(5)
    screen.update()
    [ball.move() for ball in balls]     # 每个弹球都进行移动
    
    screen.listen()
    screen.mainloop()
    
    
            

3D多彩重力弹球,这是用Python的海龟画图制作的3D多彩重力弹球