Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- BDWConfettiandSound.py +104 -0
- BalaKrishBDayWish2U.mp3 +0 -0
- TrumpWishes.mp3 +0 -0
BDWConfettiandSound.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pygame
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Initialize pygame
|
| 5 |
+
pygame.init()
|
| 6 |
+
|
| 7 |
+
# Constants
|
| 8 |
+
WIDTH, HEIGHT = 800, 600
|
| 9 |
+
LIGHT_GRAY = (211, 211, 211)
|
| 10 |
+
BLACK = (0, 0, 0)
|
| 11 |
+
|
| 12 |
+
# Screen setup
|
| 13 |
+
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
| 14 |
+
pygame.display.set_caption("HAPPY BIRTHDAY SIVA Animation")
|
| 15 |
+
|
| 16 |
+
# Load sound
|
| 17 |
+
confetti_sound = pygame.mixer.Sound('B:\Coding\Temp\BalaKrishBDayWish2U.mp3')
|
| 18 |
+
sound_played = False
|
| 19 |
+
|
| 20 |
+
# Font settings
|
| 21 |
+
message = "HAPPY BIRTHDAY SIVA"
|
| 22 |
+
font = pygame.font.SysFont(None, 40)
|
| 23 |
+
target_positions = [(WIDTH // 2 - font.size(message)[0] // 2 + font.size(message[:i])[0], HEIGHT // 2) for i, char in enumerate(message)]
|
| 24 |
+
current_positions = [(random.randint(0, WIDTH), random.randint(0, HEIGHT)) for _ in message]
|
| 25 |
+
velocities = [(random.random() - 0.5, random.random() - 0.5) for _ in message]
|
| 26 |
+
|
| 27 |
+
def move_toward(pos, target, vel):
|
| 28 |
+
x, y = pos
|
| 29 |
+
tx, ty = target
|
| 30 |
+
vx, vy = vel
|
| 31 |
+
speed = 0.00095
|
| 32 |
+
vx += (tx - x) * speed
|
| 33 |
+
vy += (ty - y) * speed
|
| 34 |
+
vx *= 0.95
|
| 35 |
+
vy *= 0.95
|
| 36 |
+
x += vx
|
| 37 |
+
y += vy
|
| 38 |
+
|
| 39 |
+
threshold = 10
|
| 40 |
+
if abs(x - tx) < threshold and abs(y - ty) < threshold:
|
| 41 |
+
x, y = tx, ty
|
| 42 |
+
|
| 43 |
+
return (x, y), (vx, vy)
|
| 44 |
+
|
| 45 |
+
class Confetti:
|
| 46 |
+
COLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0)]
|
| 47 |
+
|
| 48 |
+
def __init__(self):
|
| 49 |
+
self.x = random.randint(0, WIDTH)
|
| 50 |
+
self.y = random.randint(-20, -5) # Start slightly off-screen
|
| 51 |
+
self.color = random.choice(self.COLORS)
|
| 52 |
+
self.speed = random.uniform(1, 3)
|
| 53 |
+
|
| 54 |
+
def update(self):
|
| 55 |
+
self.y += self.speed
|
| 56 |
+
if self.y > HEIGHT:
|
| 57 |
+
self.y = random.randint(-20, -5)
|
| 58 |
+
self.x = random.randint(0, WIDTH)
|
| 59 |
+
|
| 60 |
+
def draw(self, screen):
|
| 61 |
+
pygame.draw.circle(screen, self.color, (self.x, self.y), 5)
|
| 62 |
+
|
| 63 |
+
confetti_particles = []
|
| 64 |
+
|
| 65 |
+
# Main loop
|
| 66 |
+
running = True
|
| 67 |
+
while running:
|
| 68 |
+
screen.fill(LIGHT_GRAY)
|
| 69 |
+
|
| 70 |
+
all_letters_in_place = True
|
| 71 |
+
for i, (x, y) in enumerate(current_positions):
|
| 72 |
+
(new_x, new_y), (new_vx, new_vy) = move_toward((x, y), target_positions[i], velocities[i])
|
| 73 |
+
current_positions[i] = (new_x, new_y)
|
| 74 |
+
velocities[i] = (new_vx, new_vy)
|
| 75 |
+
|
| 76 |
+
color = BLACK
|
| 77 |
+
char_surface = font.render(message[i], True, color)
|
| 78 |
+
screen.blit(char_surface, (new_x, new_y))
|
| 79 |
+
|
| 80 |
+
if new_x != target_positions[i][0] or new_y != target_positions[i][1]:
|
| 81 |
+
all_letters_in_place = False
|
| 82 |
+
|
| 83 |
+
if all_letters_in_place:
|
| 84 |
+
if not sound_played:
|
| 85 |
+
confetti_sound.play()
|
| 86 |
+
sound_played = True
|
| 87 |
+
|
| 88 |
+
# Initialize confetti particles
|
| 89 |
+
confetti_particles = [Confetti() for _ in range(100)]
|
| 90 |
+
|
| 91 |
+
# Draw and update confetti particles
|
| 92 |
+
for particle in confetti_particles:
|
| 93 |
+
particle.update()
|
| 94 |
+
particle.draw(screen)
|
| 95 |
+
|
| 96 |
+
pygame.display.flip()
|
| 97 |
+
|
| 98 |
+
for event in pygame.event.get():
|
| 99 |
+
if event.type == pygame.QUIT:
|
| 100 |
+
running = False
|
| 101 |
+
|
| 102 |
+
pygame.time.wait(10)
|
| 103 |
+
|
| 104 |
+
pygame.quit()
|
BalaKrishBDayWish2U.mp3
ADDED
|
Binary file (503 kB). View file
|
|
|
TrumpWishes.mp3
ADDED
|
Binary file (158 kB). View file
|
|
|