-
Notifications
You must be signed in to change notification settings - Fork 4
/
close_eyes.py
104 lines (64 loc) · 2.12 KB
/
close_eyes.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pygame
import time as tl
import winsound
from pygame import *
import sys
s = None
def alarm(duration=3000, freq=440):
global s
# duration = 5000 # millisecond
# freq = 440 # Hz
# winsound.Beep(freq, duration)
mixer.pre_init(frequency=44100, size=-16, channels=2, buffer=4096)
WAVFILE = './assets/music.wav'
s = pygame.mixer.Sound(WAVFILE)
# pygame.init()
ch = s.play()
def text_objects(text, font):
textSurface = font.render(text, True, (255,200,76))
return textSurface, textSurface.get_rect()
def format(num):
if num <= 9:
return '0'+str(num)
return str(num)
def close_eye_screen(count_till, text, quitf=True):
pygame.init()
width, height = 1920,1080
screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN)
running = True
largeText = pygame.font.Font('Raleway-Medium.ttf',110)
message_text = pygame.font.Font('Raleway-Medium.ttf', 65)
mess = ""
is_alarm = False
while running:
minutes = int(count_till/60)
seconds = int(count_till%60)
screen.fill((255, 255, 255))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if count_till <= 0:
running = False
TextSurf, TextRect = None, None
if count_till == 0:
mess = "Press any key to continue"
if not is_alarm:
alarm()
is_alarm = True
TextSurf, TextRect = text_objects(mess, message_text)
else:
mess = format(minutes)+":"+format(seconds)
TextSurf, TextRect = text_objects(mess, largeText)
count_till-=1
# pygame.draw.circle(screen,color, position, radius, width)
MessSurf, MessRect = text_objects(text, message_text)
MessRect.center = (950, 300)
TextRect.center = ((950),(500))
screen.blit(TextSurf, TextRect)
screen.blit(MessSurf, MessRect)
pygame.display.flip()
tl.sleep(1)
s.stop()
if quitf:
pygame.quit()
if __name__ == '__main__':
close_eye_screen(3, "Alarm")