-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_changing_dvd_screensaver.py
73 lines (59 loc) · 2.01 KB
/
color_changing_dvd_screensaver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pygame
import time
from sys import exit
def main_loop():
pygame.init()
width, height = 800, 600
dvdLogo = pygame.image.load("dvd-logo.png")
dvdLogo = pygame.transform.scale(dvdLogo, (300, 150))
dvdLogoSpeed = [1, 1]
screen = pygame.display.set_mode((width, height))
dvdLogoRect = dvdLogo.get_rect()
hits = 0
while True:
screen.fill(color_changer(hits))
screen.blit(dvdLogo, dvdLogoRect)
dvdLogoRect = dvdLogoRect.move(dvdLogoSpeed)
if dvdLogoRect.left == 0 or dvdLogoRect.right == width:
dvdLogoSpeed[0] = -dvdLogoSpeed[0]
if dvdLogoRect.top == 0 or dvdLogoRect.bottom == height:
dvdLogoSpeed[1] = -dvdLogoSpeed[1]
if dvdLogoRect.left == 0 and dvdLogoRect.bottom == height:
if hits != 2:
hits += 1
else:
hits = 0
screen.fill(color_changer(hits))
if dvdLogoRect.left == 0 and dvdLogoRect.top == 0:
if hits != 2:
hits += 1
else:
hits = 0
screen.fill(color_changer(hits))
if dvdLogoRect.right == width and dvdLogoRect.bottom == height:
if hits != 2:
hits += 1
else:
hits = 0
screen.fill(color_changer(hits))
if dvdLogoRect.right == width and dvdLogoRect.top == 0:
if hits != 2:
hits += 1
else:
hits = 0
screen.fill(color_changer(hits))
pygame.display.flip()
time.sleep(10 / 10000)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
def color_changer(hits):
backgroundColors = {"red": (255, 0, 0), "green": (0, 255, 0), "blue": (0, 0, 255)}
if hits == 0:
return backgroundColors["red"]
elif hits == 1:
return backgroundColors["green"]
elif hits == 2:
return backgroundColors["blue"]
main_loop()