Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Code snippets vol-44-snip-219
- 219-Python screensaver
- stevepython.wordpress.com
- requires:
- pip install pygame
- python.png image in current dir.
- Download 240+ no nonsense python code snippets:
- https://wp.me/Pa5TU8-1yg
- from code found here:
- https://dev.to/jcowie/creating-the--screensaver-in-pygame-3di
- """
- import time
- import pygame
- #pygame.init()
- width, height = 800, 600
- LogoSpeed = [1, 1]
- backgroundColor = 0, 0, 0
- screen = pygame.display.set_mode((width, height))
- Logo = pygame.image.load("python.png")
- LogoRect = Logo.get_rect()
- while True:
- screen.fill(backgroundColor)
- screen.blit(Logo, LogoRect)
- LogoRect = LogoRect.move(LogoSpeed)
- pygame.display.flip()
- time.sleep(2 / 1000)
- if LogoRect.left < 0 or LogoRect.right > width:
- LogoSpeed[0] = -LogoSpeed[0]
- if LogoRect.top < 0 or LogoRect.bottom > height:
- LogoSpeed[1] = -LogoSpeed[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement