Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import datetime
- import random
- # Initialize Pygame
- pygame.init()
- # Set fullscreen mode with native resolution and aspect ratio
- screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
- # Hide the mouse cursor
- pygame.mouse.set_visible(False)
- # Font for the clock/date text
- font = pygame.font.Font(None, 100) # Increased font size
- # Rainbow colors
- colors = [(255, 0, 0), (255, 127, 0), (255, 255, 0), (0, 255, 0), (0, 0, 255), (75, 0, 130)]
- color_index = 0
- # Initial position and speed of the clock
- x = screen.get_width() // 2
- y = screen.get_height() // 2
- dx = 1 # Decreased speed
- dy = 1 # Decreased speed
- # Show clock or date initially
- show_clock = True
- # Main loop
- running = True
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_SPACE:
- show_clock = not show_clock
- elif event.key == pygame.K_ESCAPE:
- running = False
- elif event.key == pygame.K_UP:
- dy = -1 # Move up
- elif event.key == pygame.K_DOWN:
- dy = 1 # Move down
- elif event.key == pygame.K_LEFT:
- dx = -1 # Move left
- elif event.key == pygame.K_RIGHT:
- dx = 1 # Move right
- # Get current time or date
- if show_clock:
- text = datetime.datetime.now().strftime("%H:%M:%S")
- else:
- text = datetime.date.today().strftime("%d/%m/%Y")
- # Render the text with bold font
- text_surface = font.render(text, True, colors[color_index])
- # Move the clock
- x += dx
- y += dy
- # Bounce off the screen edges
- if x + text_surface.get_width() > screen.get_width() or x < 0:
- dx = -dx
- color_index = (color_index + 1) % len(colors) # Change color on bounce
- if y + text_surface.get_height() > screen.get_height() or y < 0:
- dy = -dy
- color_index = (color_index + 1) % len(colors) # Change color on bounce
- # Fill the screen with black
- screen.fill((0, 0, 0))
- # Blit the text onto the screen
- screen.blit(text_surface, (x, y))
- # Update the display
- pygame.display.flip()
- # Quit Pygame
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement