forked from danbujak/pixelPerfect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clockFunc.py
138 lines (111 loc) · 3.89 KB
/
clockFunc.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
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
133
134
135
136
137
138
#!/usr/bin/python
from clockParams import *
from configs import *
import datetime
from decimal import Decimal
# ---------------- Clock digit locations and sizes --------------------
HOUR1_X = 3
HOUR1_Y = 1
HOUR2_X = 14
HOUR2_Y = 1
HOUR_DIGIT_X = 9
HOUR_DIGIT_Y = 14
MIN1_X = 3
MIN1_Y = 17
MIN2_X = 11
MIN2_Y = 17
MIN_DIGIT_X = 7
MIN_DIGIT_Y = 12
SEC1_X = 22
SEC1_Y = 21
SEC2_X = 26
SEC2_Y = 21
SEC_DIGIT_X = 3
SEC_DIGIT_Y = 5
# ---------------------------------------------------------------------
timeAM = datetime.time(TIME_AM/100, TIME_AM%100)
timeNoon = datetime.time(TIME_NOON/100, TIME_NOON%100)
timePM = datetime.time(TIME_PM/100, TIME_PM%100)
timeNight = datetime.time(TIME_NIGHT/100, TIME_NIGHT%100)
'''Set background colour based on time of day'''
def Time_to_Colour(currentTime):
if (currentTime < timeAM):
return COLOR_NIGHT
elif (currentTime < timeNoon):
t1 = timeAM
t2 = timeNoon
color1 = COLOR_AM
color2 = COLOR_NOON
elif (currentTime < timePM):
t1 = timeNoon
t2 = timePM
color1 = COLOR_NOON
color2 = COLOR_PM
elif (currentTime < timeNight):
t1 = timePM
t2 = timeNight
color1 = COLOR_PM
color2 = COLOR_NIGHT
else:
return COLOR_OFF
t1 = (t1.hour * 3600) + (t1.minute * 60) + t1.second
t2 = (t2.hour * 3600) + (t2.minute * 60) + t2.second
currentTime = (currentTime.hour * 3600) + (currentTime.minute * 60) + currentTime.second
percent = round(100 * Decimal(currentTime - t1) / Decimal(t2 - t1), 2)
return Colour_Gradient(color1, color2, percent)
'''Gradient colour based on 2 colours and percentage between them'''
def Colour_Gradient(color1, color2, percent):
r1 = int(color1[0:2], 16)
g1 = int(color1[2:4], 16)
b1 = int(color1[4:6], 16)
r2 = int(color2[0:2], 16)
g2 = int(color2[2:4], 16)
b2 = int(color2[4:6], 16)
r = r1 + ((r2 - r1) * percent /100)
g = g1 + ((g2 - g1) * percent /100)
b = b1 + ((b2 - b1) * percent /100)
#print ("%0.2X" % r) + ("%0.2X" % g) + ("%0.2X" % b)
return ("%0.2X" % r) + ("%0.2X" % g) + ("%0.2X" % b)
''' Augment a blank background frame with current time digits '''
def generate_clock_frame(currentTime, clockFrame, np, colour):
r = int(colour[0:2], 16)
g = int(colour[2:4], 16)
b = int(colour[4:6], 16)
onPixel = np.array([r,g,b])
#Hour 1
digit = np.array(LARGE_NUMBERS[int(currentTime.hour / 10)])
for y in range (0, HOUR_DIGIT_Y):
for x in range(0, HOUR_DIGIT_X):
if (digit[y,x] == 1):
clockFrame[y + HOUR1_Y, x + HOUR1_X] = onPixel
#Hour 2
digit = np.array(LARGE_NUMBERS[currentTime.hour % 10])
for y in range (0, HOUR_DIGIT_Y):
for x in range(0, HOUR_DIGIT_X):
if (digit[y,x] == 1):
clockFrame[y + HOUR2_Y, x + HOUR2_X] = onPixel
#Minute 1
digit = np.array(MEDIUM_NUMBERS[int(currentTime.minute / 10)])
for y in range (0, MIN_DIGIT_Y):
for x in range(0, MIN_DIGIT_X):
if (digit[y,x] == 1):
clockFrame[y + MIN1_Y, x + MIN1_X] = onPixel
#Minute 2
digit = np.array(MEDIUM_NUMBERS[currentTime.minute % 10])
for y in range (0, MIN_DIGIT_Y):
for x in range(0, MIN_DIGIT_X):
if (digit[y,x] == 1):
clockFrame[y + MIN2_Y, x + MIN2_X] = onPixel
#Second 1
digit = np.array(SMALL_NUMBERS[int(currentTime.second / 10)])
for y in range (0, SEC_DIGIT_Y):
for x in range(0, SEC_DIGIT_X):
if (digit[y,x] == 1):
clockFrame[y + SEC1_Y, x + SEC1_X] = onPixel
#Second 2
digit = np.array(SMALL_NUMBERS[currentTime.second % 10])
for y in range (0, SEC_DIGIT_Y):
for x in range(0, SEC_DIGIT_X):
if (digit[y,x] == 1):
clockFrame[y + SEC2_Y, x + SEC2_X] = onPixel
return clockFrame