Spaces:
Runtime error
Runtime error
| import pygame | |
| import random | |
| import os | |
| file_path = os.path.join(os.getcwd(), 'BalaKrishBDayWish2U.mp3') | |
| pygame.mixer.init() | |
| pygame.init() | |
| # Colors | |
| WHITE = (255, 255, 255) | |
| COLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (255, 0, 255)] | |
| # Screen dimensions | |
| WIDTH = 800 | |
| HEIGHT = 600 | |
| # Create the screen and clock | |
| screen = pygame.display.set_mode((WIDTH, HEIGHT)) | |
| pygame.display.set_caption("Happy Birthday!") | |
| clock = pygame.time.Clock() | |
| # Define the Font | |
| font = pygame.font.SysFont(None, 56) | |
| # Text data | |
| name = "SIVA" | |
| texts = ["Happy", "Birthday", name] | |
| class BouncingText: | |
| def __init__(self, text, target_x, target_y): | |
| self.text = font.render(text, True, (0, 128, 0)) | |
| self.rect = self.text.get_rect(center=(random.randint(0, WIDTH), random.randint(0, HEIGHT))) | |
| self.target = pygame.Vector2(target_x, target_y) | |
| self.pos = pygame.Vector2(self.rect.center) | |
| self.speed = 2.0 | |
| def update(self): | |
| direction = (self.target - self.pos).normalize() * self.speed | |
| self.pos += direction | |
| self.rect.center = self.pos | |
| def draw(self, screen): | |
| screen.blit(self.text, self.rect) | |
| def draw_confetti(screen): | |
| for _ in range(10): # drawing 10 confetti pieces per frame for effect | |
| color = random.choice(COLORS) | |
| pygame.draw.circle(screen, color, (random.randint(0, WIDTH), random.randint(0, HEIGHT)), 5) | |
| def main(): | |
| greetings = [ | |
| BouncingText("Happy", WIDTH * 0.25, HEIGHT / 2), | |
| BouncingText("Birthday", WIDTH * 0.5, HEIGHT / 2), | |
| BouncingText(name, WIDTH * 0.75, HEIGHT / 2) | |
| ] | |
| # Play the song | |
| pygame.mixer.music.load(file_path) | |
| # pygame.mixer.music.load('**\BalaKrishBDayWish2U.mp3') # replace with your mp3 file path | |
| pygame.mixer.music.play() | |
| running = True | |
| while running: | |
| screen.fill(WHITE) | |
| for event in pygame.event.get(): | |
| if event.type == pygame.QUIT: | |
| running = False | |
| for greeting in greetings: | |
| greeting.update() | |
| greeting.draw(screen) | |
| draw_confetti(screen) | |
| pygame.display.flip() | |
| clock.tick(60) | |
| pygame.quit() | |
| if __name__ == "__main__": | |
| main() | |