#!/usr/bin/python3
import pygame
import random
import time
import sys
import os
import signal
pygame.init
fireworks = []
explosions = []
stopped = False
#screenInfo = pygame.display.Info()
pygame.display.set_mode((0,0)) #
clock = pygame.time.Clock()
screen = pygame.display.get_surface()
w,h = screen.get_size()
ident = os.environ.get('XSCREENSAVER_WINDOW')
if ident is None:
pygame.display.toggle_fullscreen()
def createFireworks():
fireworks.append({
"rect" : pygame.Rect(
random.randint(0,w),
800,
10,
10
),
"color" : (random.randint(0,255),random.randint(0,255),random.randint(0,255)),
"maxHeight" : random.randint(0,800)
})
def explode(firework):
for i in range(random.randint(0,40)):
explosions.append({
"rect" : firework["rect"].copy(),
"color" : (random.randint(0,255),random.randint(0,255),random.randint(0,255)),
"dirr" : (random.randint(-10,10),random.randint(-10,10)),
"life" : random.randint(30,32)
})
while not stopped:
screen.fill((0,0,0))
lastFrame = clock.tick(30) #get the time since last frame and set the FPS correctly
#call update here.
if len(fireworks)<10:
if random.randint(0,1):
createFireworks()
newFireWorkList =[]
for firework in fireworks:
firework["rect"].y -=5
if firework["maxHeight"] >= firework["rect"].y:
explode(firework)
else:
newFireWorkList.append(firework)
pygame.draw.rect(screen,firework["color"],firework["rect"])
fireworks = newFireWorkList
newExplosionList = []
for explosion in explosions:
explosion["rect"].x += explosion["dirr"][0]
explosion["rect"].y += explosion["dirr"][1]
explosion["life"] -=1
if explosion["life"] >=0:
newExplosionList.append(explosion)
pygame.draw.rect(screen,explosion["color"],explosion["rect"])
#draw all the elements to the screen
for event in pygame.event.get():
if event.type == pygame.QUIT:
stopped = True
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
stopped = True
pygame.display.update()
#pygame.display.flip() #create the frame
#clean exit
pygame.quit()
quit()