summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Guschin <guschin.drew@gmail.com>2024-02-24 09:19:01 +0400
committerAndrew Guschin <guschin.drew@gmail.com>2024-02-24 09:19:01 +0400
commit076122c6347e464ab9685a168d8ec9db389ba31c (patch)
tree4a0728e6646e7d8f95202cf1251c46549aca2a13
-rwxr-xr-xGraph.ttfbin0 -> 56644 bytes
-rw-r--r--bg.pngbin0 -> 263304 bytes
-rw-r--r--requirements.txt1
-rw-r--r--timer.py89
4 files changed, 90 insertions, 0 deletions
diff --git a/Graph.ttf b/Graph.ttf
new file mode 100755
index 0000000..7c18700
--- /dev/null
+++ b/Graph.ttf
Binary files differ
diff --git a/bg.png b/bg.png
new file mode 100644
index 0000000..2dfdcd4
--- /dev/null
+++ b/bg.png
Binary files differ
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..b4fe918
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+pygame==2.1.2
diff --git a/timer.py b/timer.py
new file mode 100644
index 0000000..8a076d3
--- /dev/null
+++ b/timer.py
@@ -0,0 +1,89 @@
+import pygame as pg
+from pygame.locals import *
+import os
+import random as rng
+import datetime as dtm
+
+
+
+BLACK = Color("black")
+RED = Color(200, 0, 0)
+GREEN = Color(0, 200, 0)
+BLUE = Color(0, 0, 200)
+WHITE = Color("white")
+
+
+def to_hms(diff):
+ sec = int(diff.total_seconds())
+ hours = sec // 3600
+ minutes = (sec - hours * 3600) // 60
+ seconds = sec % 60
+ return hours, minutes, seconds
+
+
+def format_timer(hms):
+ hours, minutes, seconds = hms
+ return "{}:{}:{}".format(
+ str(hours).rjust(2, '0'),
+ str(minutes).rjust(2, '0'),
+ str(seconds).rjust(2, '0'),
+ )
+
+def center_place(screen_w, screen_h, surf):
+ surf_w, surf_h = surf.get_size()
+ return (
+ (screen_w - surf_w) // 2,
+ (screen_h - surf_h) // 2,
+ )
+
+pg.init()
+w, h = size = 1440, 900
+isfull = False
+screen = pg.display.set_mode(size)
+font_size = 170
+pg.display.set_caption("Таймер хакатона")
+
+title_font = pg.font.Font("Graph.ttf", 80)
+main_font = pg.font.Font("Graph.ttf", font_size)
+
+bg_color = WHITE
+bg = pg.image.load("bg.png")
+
+hackend = dtm.datetime(year=2024, month=2, day=25, hour=17, minute=0)
+
+running = True
+while running:
+ for event in pg.event.get():
+ if event.type == QUIT:
+ running = False
+
+ if event.type == KEYDOWN:
+ if event.key == K_ESCAPE:
+ running = False
+ if event.key == K_SPACE:
+ if isfull:
+ pg.display.set_mode(size, 0)
+ isfull = False
+ else:
+ pg.display.set_mode(size, FULLSCREEN)
+ isfull = True
+
+ screen.fill(BLACK)
+ screen.blit(bg, (0, 0))
+
+
+ now = dtm.datetime.now()
+ diff = hackend - now
+ hms = to_hms(diff)
+ timer_txt = format_timer(hms)
+ text = main_font.render(timer_txt, True, WHITE)
+ text_place = center_place(*size, text)
+ screen.blit(text, text_place)
+
+ title = title_font.render("До конца хакатона", True, WHITE)
+ title_place = center_place(*size, title)
+ title_place = (title_place[0], title_place[1] - 170)
+ screen.blit(title, title_place)
+
+ pg.display.flip()
+