Skip to content

Instantly share code, notes, and snippets.

@nitori
Last active February 4, 2023 21:43
Show Gist options
  • Save nitori/18dd5ceb539b3fa124761f1825d3bf26 to your computer and use it in GitHub Desktop.
Save nitori/18dd5ceb539b3fa124761f1825d3bf26 to your computer and use it in GitHub Desktop.
Allows showing what the current time would be if we used different conversion from seconds to minutes to hours.
from __future__ import annotations
import pygame
import math
from datetime import datetime
HOURS_PER_DAY = 10
MINUTES_PER_HOUR = 100
SECONDS_PER_MINUTE = 100
def main():
pygame.init()
screen = pygame.display.set_mode((1024, 400))
clock = pygame.time.Clock()
seconds_per_hour = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
seconds_per_day = HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE
font_clock = pygame.font.SysFont('Monospace', size=100)
font_s = pygame.font.SysFont('Monospace', size=18)
hour_digits = math.ceil(math.log10(HOURS_PER_DAY))
minute_digits = math.ceil(math.log10(MINUTES_PER_HOUR))
second_digits = math.ceil(math.log10(SECONDS_PER_MINUTE))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return
now = datetime.now()
today = datetime(now.year, now.month, now.day, 0, 0, 0, 0)
old_seconds = (now - today).total_seconds()
new_seconds = int(seconds_per_day / 86400 * old_seconds)
s_surf1 = font_s.render(f'{new_seconds:_d}/{seconds_per_day:_d}', True, 'white')
s_surf2 = font_s.render(f'{int(old_seconds):_d}/{86400:_d}', True, 'white')
hours, seconds = divmod(new_seconds, seconds_per_hour)
minutes, seconds = divmod(seconds, SECONDS_PER_MINUTE)
text = f'{hours:0{hour_digits}d}:{minutes:0{minute_digits}d}:{seconds:0{second_digits}d}'
clock_surf = font_clock.render(text, True, 'white')
top = (screen.get_height() - clock_surf.get_height()) // 2
left = (screen.get_width() - clock_surf.get_width()) // 2
old_seconds = int(old_seconds)
old_hours, old_seconds = divmod(old_seconds, 3600)
old_minutes, old_seconds = divmod(old_seconds, 60)
clock_orig_surf = font_s.render(f'{old_hours:02d}:{old_minutes:02d}:{old_seconds:02d}', True, 'white')
orig_left = (screen.get_width() - clock_orig_surf.get_width()) // 2
orig_top = top + clock_surf.get_height()
screen.fill('black')
screen.blit(clock_surf, (left, top))
screen.blit(clock_orig_surf, (orig_left, orig_top))
screen.blit(s_surf1, (10, 10))
screen.blit(s_surf2, (10, 35))
clock.tick(30)
pygame.display.flip()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment