-
Notifications
You must be signed in to change notification settings - Fork 2
/
clock.py
69 lines (65 loc) · 2.8 KB
/
clock.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
import os
import pygame
import time
import random
import math
from time import strftime, localtime
from screen import screen
screen = screen()
pygame.mouse.set_visible(0)
font = pygame.font.Font('segoeui.ttf', 90)
bkgcolor = (70, 70, 70)
fgcolor = (255, 255, 255)
buffer = 50
circleY = 700
circleRadius = 5
dots = 20
def dw(texts, ons, y):
rs = []
totalwidth = 0
for (i, text) in enumerate(texts):
r = font.render(text, True, bkgcolor)
rs.append(r)
totalwidth += r.get_width()
leftover = (1280 - totalwidth - (buffer * 2)) / len(texts)
offset = buffer
for (i, r) in enumerate(rs):
screen.scr.blit(r, (offset, y))
if(ons[i] == 1):
screen.scr.blit(font.render(texts[i], True, fgcolor), (offset, y))
offset += r.get_width() + leftover
def drawDotLine():
second = int(strftime("%S", localtime()))
circleSpace = (1280 - (buffer * 2)) / (dots - 1)
offset = buffer
for x in range(0, dots):
if(second / (60 / dots) >= x):
pygame.draw.circle(screen.scr, fgcolor, (offset, circleY), circleRadius, 0)
else:
pygame.draw.circle(screen.scr, bkgcolor, (offset, circleY), circleRadius, 0)
offset += circleSpace
while 1:
screen.scr.fill((0,0,0))
line1 = 10
line2 = 120
line3 = 230
line4 = 340
line5 = 450
line6 = 560
hour = int(strftime("%I", localtime()))
minute = int(strftime("%M", localtime()))
if(minute >= 35):
hour = (1 if hour == 12 else hour + 1)
dw(["it", "is", "half", "ten"], [1,1,(1 if minute >= 30 and minute < 35 else 0),
(1 if (minute >= 10 and minute < 15) or (minute >=50 and minute < 55) else 0)], line1)
dw(["quarter", "twenty", "five"], [
(1 if minute >= 15 and minute < 20 or minute >= 45 and minute < 50 else 0),
(1 if minute >= 20 and minute < 30 or minute >= 35 and minute < 45 else 0),
(1 if minute >= 5 and minute < 10 or minute >= 25 and minute < 30 or minute >= 35 and minute < 40 or minute >= 55 else 0)], line2)
dw(["minutes", "to", "past", "one"], [(1 if minute >= 35 and minute < 45 or minute >= 50 else 0),(1 if minute >= 35 else 0),(1 if minute < 35 and minute >= 5 else 0),(1 if hour == 1 else 0)], line3)
dw(["three", "two", "four", "five"], [(1 if hour == 3 else 0),(1 if hour == 2 else 0),(1 if hour == 4 else 0),(1 if hour == 5 else 0)], line4)
dw(["six", "seven", "eight", "nine"], [(1 if hour == 6 else 0),(1 if hour == 7 else 0),(1 if hour == 8 else 0),(1 if hour == 9 else 0)], line5)
dw(["ten", "eleven", "twelve", "o'clock"], [(1 if hour == 10 else 0),(1 if hour == 11 else 0),(1 if hour == 12 else 0),(1 if minute >= 0 and minute < 5 else 0)], line6)
drawDotLine()
pygame.display.update()
time.sleep(1)