-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (67 loc) · 2.68 KB
/
main.py
File metadata and controls
79 lines (67 loc) · 2.68 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
import shutil
import numpy as np
import time
import sys
import wavey
from digits import DIGITS
class Clock:
def __init__(self):
try:
self.width, self.height = shutil.get_terminal_size((80, 24))
except:
self.width, self.height = 80, 24
self.x = np.linspace(0, 7, self.width)
self.y = np.linspace(0, 7, self.height)
self.xx, self.yy = np.meshgrid(self.x, self.y)
self.bg = wavey.bg()
def draw_big_clock(self, frame):
time_str = time.strftime("%I:%M %p")
rows = len(frame)
cols = len(frame[0]) if rows > 0 else 0
clock_width = len(time_str) * 8 # every digit is 7 wide + 1 space
clock_height = 7
start_row = int((rows - clock_height) / 2)
start_col = int((cols - clock_width) / 2)
if start_row < 0 or start_col < 0:
return frame # toooo smallll
for i, char in enumerate(time_str):
# print(char)
if char not in DIGITS:
continue
digit = DIGITS[char]
for y, line in enumerate(digit):
for x, block in enumerate(line):
if block == '█':
frame_row = start_row + y
frame_col = start_col + x + (i * 8)
if 0 <= frame_row < rows and 0 <= frame_col < cols:
frame[frame_row] = (
frame[frame_row][:frame_col] + # everything before
"█" +
frame[frame_row][frame_col+1:] # everything after
)
return frame
def draw(self):
wave = self.bg.generate_wave(self.xx, self.yy)
frame = ["".join(row) for row in wave]
frame = self.draw_big_clock(frame)
sys.stdout.write("\033[H") # Move cursor home
sys.stdout.write("\n".join(frame))
sys.stdout.flush()
def run (self):
while True:
current_size = shutil.get_terminal_size().columns, shutil.get_terminal_size().lines
if current_size != (self.width, self.height):
try:
self.width, self.height = shutil.get_terminal_size((80, 24))
except:
self.width, self.height = 80, 24
x = np.linspace(0, 7, self.width)
y = np.linspace(0, 7, self.height)
self.xx, self.yy = np.meshgrid(x, y)
self.bg.time += 0.1 * 1
self.draw()
time.sleep(0.05)
if __name__ == "__main__":
c = Clock()
c.run()