该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
"""
下雨了
"""
import pygame #导入pygame模块
import random #导入random模块
pygame.init() #初始化Pygame
screen = pygame.display.set_mode([800, 600]) #创建一个宽800像素高600像素的显示窗口
keep_going = True #布尔值控制游戏循环
BLACK = (0, 0, 0) #定义黑色RGB值
colors = [0] * 100 #初始化100个颜色
locations = [0] * 100 #初始化100个坐标
sizes = [0] * 100 #初始化100个大小
for n in range(100): #循环100次
colors[n] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) #为100个颜色赋值随机RGB颜色
locations[n] = (random.randint(0, 800), random.randint(0, 600)) #为100个位置赋值800*600内的随机坐标
sizes[n] = random.randint(10, 100) #为100个大小赋值随机10-100的整数
while keep_going: #游戏循环
for event in pygame.event.get(): #处理所有触发的交互事件
if event.type == pygame.QUIT: #点击退出
keep_going = False #退出循环
for n in range(100): #循环100次
pygame.draw.circle(screen, colors[n], locations[n], sizes[n]) #画第n个随机圆
new_x = locations[n][0] + 1 #x坐标+1
new_y = locations[n][1] + 1 #y坐标+1
if new_x > 800: #如果飞出了右屏幕,则回到左屏幕
new_x -= 800
if new_y > 600: #如果飞出了下屏幕,则回到上屏幕
new_y -= 600
locations[n] = (new_x, new_y) #更新100个坐标
pygame.display.update() #刷新屏幕
screen.fill(BLACK) #全屏涂黑,达到清屏效果,以产生动画效果
pygame.quit() #退出游戏