-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
132 lines (99 loc) · 3.41 KB
/
timer.py
File metadata and controls
132 lines (99 loc) · 3.41 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3
import math
import os
import time
try:
import pygame
except ImportError:
os.system('start cmd /c pip3 install pygame')
import pygame
pygame.init()
pygame.display.set_caption('Timer')
screen = pygame.display.set_mode((500, 600))
GREY = (150, 150, 150)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
running = True
start = False
totalSecs = 0
totalTime = 0
font = pygame.font.SysFont('sans', 50)
textPlus = font.render('+', True, BLACK)
textMinus = font.render('-', True, BLACK)
textStart = font.render('Start', True, BLACK)
textReset = font.render('Reset', True, BLACK)
clock = pygame.time.Clock()
while running:
clock.tick(60)
screen.fill(GREY)
sound = pygame.mixer.Sound('alarm.wav')
mouseX, mouseY = pygame.mouse.get_pos()
pygame.draw.rect(screen, BLACK, (95 , 45 , 60 , 60))
pygame.draw.rect(screen, WHITE, (100, 50 , 50 , 50))
pygame.draw.rect(screen, BLACK, (95 , 195, 60 , 60))
pygame.draw.rect(screen, WHITE, (100, 200, 50 , 50))
pygame.draw.rect(screen, BLACK, (195, 45 , 60 , 60))
pygame.draw.rect(screen, WHITE, (200, 50 , 50 , 50))
pygame.draw.rect(screen, BLACK, (195, 195, 60 , 60))
pygame.draw.rect(screen, WHITE, (200, 200, 50 , 50))
pygame.draw.rect(screen, BLACK, (295, 45 , 160, 60))
pygame.draw.rect(screen, WHITE, (300, 50 , 150, 50))
pygame.draw.rect(screen, BLACK, (295, 145, 160, 60))
pygame.draw.rect(screen, WHITE, (300, 150, 150, 50))
pygame.draw.rect(screen, BLACK, (55 , 525, 390, 40))
pygame.draw.rect(screen, WHITE, (60 , 530, 380, 30))
pygame.draw.circle(screen, BLACK, (250, 400), 100)
pygame.draw.circle(screen, WHITE, (250, 400), 95 )
pygame.draw.circle(screen, BLACK, (250, 400), 5 )
screen.blit(textPlus, (115, 45))
screen.blit(textPlus, (215, 45))
screen.blit(textMinus, (120, 190))
screen.blit(textMinus, (220, 190))
screen.blit(textStart, (330, 50 ))
screen.blit(textReset, (320, 150))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
pygame.mixer.pause()
if start == False:
if 100 < mouseX < 150 and 50 < mouseY < 100:
totalSecs += 60
if 100 < mouseX < 150 and 200 < mouseY < 250:
totalSecs -= 60
if 200 < mouseX < 250 and 50 < mouseY < 100:
totalSecs += 1
if 200 < mouseX < 250 and 200 < mouseY < 250:
totalSecs -= 1
if 300 < mouseX < 450 and 50 < mouseY < 100:
totalTime = totalSecs
start = True
if 300 < mouseX < 450 and 150 < mouseY < 200:
totalSecs = 0
if start:
totalSecs -= 1
time.sleep(1 / 1000)
if totalSecs <= 0:
pygame.mixer.Sound.play(sound)
start = False
if totalSecs < 0:
totalSecs = 0
if totalSecs == 0:
totalTime = 0
mins = totalSecs // 60
secs = totalSecs % 60
curTime = str(mins).zfill(2) + " : " + str(secs).zfill(2)
textTime = font.render(curTime, True, BLACK)
screen.blit(textTime, (110, 120))
xSec = int(250 + 90 * math.sin(6 * secs * math.pi / 180))
ySec = int(400 - 90 * math.cos(6 * secs * math.pi / 180))
pygame.draw.line(screen, BLACK, (250, 400), (xSec, ySec), 2)
xMin = int(250 + 60 * math.sin(6 * mins * math.pi / 180))
yMin = int(400 - 60 * math.cos(6 * mins * math.pi / 180))
pygame.draw.line(screen, RED , (250, 400), (xMin, yMin), 3)
if totalTime != 0:
pygame.draw.rect(screen, RED, (60, 530, int(totalSecs / totalTime * 380), 30))
pygame.display.flip()
pygame.quit()