Advertisement
Guest User

Untitled

a guest
Feb 25th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import pygame
  2. import datetime
  3. import random
  4.  
  5. # Initialize Pygame
  6. pygame.init()
  7.  
  8. # Set fullscreen mode with native resolution and aspect ratio
  9. screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
  10.  
  11. # Hide the mouse cursor
  12. pygame.mouse.set_visible(False)
  13.  
  14. # Font for the clock/date text
  15. font = pygame.font.Font(None, 100) # Increased font size
  16.  
  17. # Rainbow colors
  18. colors = [(255, 0, 0), (255, 127, 0), (255, 255, 0), (0, 255, 0), (0, 0, 255), (75, 0, 130)]
  19. color_index = 0
  20.  
  21. # Initial position and speed of the clock
  22. x = screen.get_width() // 2
  23. y = screen.get_height() // 2
  24. dx = 1 # Decreased speed
  25. dy = 1 # Decreased speed
  26.  
  27. # Show clock or date initially
  28. show_clock = True
  29.  
  30. # Main loop
  31. running = True
  32. while running:
  33. for event in pygame.event.get():
  34. if event.type == pygame.QUIT:
  35. running = False
  36. elif event.type == pygame.KEYDOWN:
  37. if event.key == pygame.K_SPACE:
  38. show_clock = not show_clock
  39. elif event.key == pygame.K_ESCAPE:
  40. running = False
  41. elif event.key == pygame.K_UP:
  42. dy = -1 # Move up
  43. elif event.key == pygame.K_DOWN:
  44. dy = 1 # Move down
  45. elif event.key == pygame.K_LEFT:
  46. dx = -1 # Move left
  47. elif event.key == pygame.K_RIGHT:
  48. dx = 1 # Move right
  49.  
  50. # Get current time or date
  51. if show_clock:
  52. text = datetime.datetime.now().strftime("%H:%M:%S")
  53. else:
  54. text = datetime.date.today().strftime("%d/%m/%Y")
  55.  
  56. # Render the text with bold font
  57. text_surface = font.render(text, True, colors[color_index])
  58.  
  59. # Move the clock
  60. x += dx
  61. y += dy
  62.  
  63. # Bounce off the screen edges
  64. if x + text_surface.get_width() > screen.get_width() or x < 0:
  65. dx = -dx
  66. color_index = (color_index + 1) % len(colors) # Change color on bounce
  67. if y + text_surface.get_height() > screen.get_height() or y < 0:
  68. dy = -dy
  69. color_index = (color_index + 1) % len(colors) # Change color on bounce
  70.  
  71. # Fill the screen with black
  72. screen.fill((0, 0, 0))
  73.  
  74. # Blit the text onto the screen
  75. screen.blit(text_surface, (x, y))
  76.  
  77. # Update the display
  78. pygame.display.flip()
  79.  
  80. # Quit Pygame
  81. pygame.quit()
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement