pygame仿3D星空_右出.py

pygame仿3D星空_右出.py

以下是部分代码预览:

"""仿3D星空.py,本程序定义了一个Dot类,点越大,移动的速度越快,所以有种3D效果"""

__author__ = "李兴球"
__date__  = "2018年6月"
__company__ = "风火轮少儿编程"

import pygame
from pygame.locals import *
from random import randint

class Dot():
    def __init__(self,r,screen):
        self.radius = r   # 半径
        self.screen = screen        
        self.sw = screen.get_width()
        self.sh = screen.get_height()
        self.image = pygame.Surface((2*r,2*r))     # 建立表面,长宽为2*r,2*r
        self.image.set_colorkey((0,0,0))           # 设置表面的透明色
        pass    

def main():

    pygame.init()
    title = "3D星空_点类:作者:李兴球 www.scratch8.net"
    screen_width,screen_height = 480,360
    screen = pygame.display.set_mode((screen_width,screen_height)) 

    t = pygame.time.Clock()    
    dotList = []
    running = True
    while running:
        dotList.append(Dot(randint(1,4),screen))
        for event in pygame.event.get():
            if event.type == QUIT:running = False
        pygame.display.set_caption(title + str(pygame.mouse.get_pos()))
        pass       
        pygame.display.update()
        t.tick(30)                 # fps每秒显示30帧
    pygame.quit()
    

if __name__ =="__main__":
    main()
        

如需要查看完整代码,请

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

李兴球

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