Advertisement
steve-shambles-2109

219-Python screensaver

Feb 29th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. """Code snippets vol-44-snip-219
  2. 219-Python screensaver
  3. stevepython.wordpress.com
  4.  
  5. requires:
  6. pip install pygame
  7. python.png image in current dir.
  8.  
  9. Download 240+ no nonsense python code snippets:
  10. https://wp.me/Pa5TU8-1yg
  11.  
  12. from code found here:
  13. https://dev.to/jcowie/creating-the--screensaver-in-pygame-3di
  14. """
  15. import time
  16. import pygame
  17.  
  18. #pygame.init()
  19. width, height = 800, 600
  20. LogoSpeed = [1, 1]
  21. backgroundColor = 0, 0, 0
  22.  
  23. screen = pygame.display.set_mode((width, height))
  24.  
  25. Logo = pygame.image.load("python.png")
  26. LogoRect = Logo.get_rect()
  27.  
  28. while True:
  29.     screen.fill(backgroundColor)
  30.  
  31.     screen.blit(Logo, LogoRect)
  32.     LogoRect = LogoRect.move(LogoSpeed)
  33.  
  34.     pygame.display.flip()
  35.     time.sleep(2 / 1000)
  36.  
  37.     if LogoRect.left < 0  or LogoRect.right > width:
  38.         LogoSpeed[0] = -LogoSpeed[0]
  39.     if LogoRect.top < 0  or LogoRect.bottom > height:
  40.         LogoSpeed[1] = -LogoSpeed[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement