This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fireworkDisplay.py
161 lines (119 loc) · 3.6 KB
/
fireworkDisplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import pygame
import random
import math
import sys
import time
from pygame import mixer
# Define some colors
CLTGREEN = (0, 80, 53)
NINERGOLD = (164, 150, 101)
WHITE = (255, 255, 255)
JASPER = (241, 230, 178)
PINEGREEN = (137, 144, 100)
CLAYRED = (128, 47, 45)
SKYBLUE = (0, 115, 119)
OREBLACK = (16, 24, 32)
BLACK = (0, 0, 0)
def end_game():
pygame.quit()
sys.exit()
start_time = round(time.time())
stop_after = start_time + 5 # 5 seconds
# GRR logo
GRR_png = pygame.image.load("fireworkDisplay.png")
img_size = GRR_png.get_rect().size
# Define the particle class
class Particle:
def __init__(self, x, y, color, angle):
self.x = x
self.y = y
self.color = color
self.angle = angle
self.speed = random.randint(1, 5)
def update(self):
self.x += self.speed * math.cos(math.radians(self.angle))
self.y -= self.speed * math.sin(math.radians(self.angle))
self.speed -= 0.1
def draw(self, screen):
pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), 3)
# Define the explosion class
class Explosion:
def __init__(self, x, y):
self.particles = []
for i in range(100):
color = random.choice([WHITE, JASPER, PINEGREEN, CLAYRED, SKYBLUE, OREBLACK])
angle = random.randint(0, 360)
self.particles.append(Particle(x, y, color, angle))
def update(self):
for particle in self.particles:
particle.update()
def draw(self, screen):
for particle in self.particles:
particle.draw(screen)
# Define the main function
def main():
pygame.init()
info_object = pygame.display.Info()
width = info_object.current_w
height = info_object.current_h
global alpha
alpha = 255
x_speed = 18
y_speed = 14
x = random.randint(1, 1)
y = random.randint(1, 1)
# Initialize Pygame
mixer.init()
mixer.music.load("fireworkDisplay.mp3")
mixer.music.set_volume(0.5)
mixer.music.play()
# Set the dimensions of the window
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
# alpha of logo
GRR_png.set_alpha(alpha)
# Set the caption of the window
pygame.display.set_caption("Celebratory Fireworks")
# Set up the clock
clock = pygame.time.Clock()
# Set up the list of explosions
explosions = []
# Set up the game loop
done = False
while not done:
# Handle events
current_time = round(time.time())
if current_time >= stop_after:
end_game()
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Create a new explosion
if random.random() < 0.25: # frequency of fireworks
explosions.append(Explosion(random.randint(0, width), random.randint(0, height)))
# Update the explosions
for explosion in explosions:
explosion.update()
# Draw the background
screen.fill(BLACK)
# Draw the explosions
for explosion in explosions:
explosion.draw(screen)
# Update the screen
if (x + img_size[0] >= width) or (x <= 0):
x_speed = -x_speed
if (y + img_size[1] >= height) or (y <= 0):
y_speed = -y_speed
x += x_speed
y += y_speed
GRR_png.set_alpha(alpha)
screen.blit(GRR_png, (x, y))
# decrease opacity
alpha -= 1
pygame.display.flip()
# Tick the clock
clock.tick(60)
# Quit Pygame
pygame.quit()
# Call the main function
if __name__ == "__main__":
main()