-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpymatrix.py
118 lines (83 loc) · 3.09 KB
/
pymatrix.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
#!/usr/bin/env python3
import threading
import random
import time
import os
import curses
lock = threading.RLock()
cond = threading.Condition()
event = threading.Event()
class playground(object):
def __init__(self, stdscr):
self.stdscr = stdscr
maxLine = curses.LINES
maxColumn = curses.COLS
random.seed()
self.top = int(maxLine * 0.1)
self.bottom = int(maxLine * 0.8)
self.left = int(maxColumn * 0.1)
self.right = int(maxColumn * 0.9)
curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.curs_set(False)
self.__drawboder(stdscr, self.top, self.bottom, self.left, self.right)
#threading.Thread(target=self.__monitor, daemon=True).start()
def __drawboder(self, stdscr, top, bottom, left, right):
stdscr.addstr(top, left, "+")
stdscr.addstr(bottom, left, "+")
stdscr.addstr(top, right, "+")
stdscr.addstr(bottom, right, "+")
for i in range(top + 1, bottom):
stdscr.addstr(i, left, "|")
stdscr.addstr(i, right, "|")
for i in range(left + 1, right):
stdscr.addstr(top, i, "-")
stdscr.addstr(bottom, i, "-")
stdscr.refresh()
def __monitor(self):
# self.stdscr.move(0,0)
while True:
self.stdscr.nodelay(True)
with lock:
ch = self.stdscr.getch()
if ch == ord('q'):
event.set()
curses.endwin()
os.system("clear")
break
def matrix(self):
attr = curses.color_pair(2)
length = random.randint(1, 15)
position = []
name = threading.current_thread().name
def gen_bin(length):
binary = []
for i in range(length):
binary.append(random.choice(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ&%$#@!~1234567890"))
while True:
yield from binary
message = gen_bin(length)
time.sleep(random.randint(0, 5000) * 0.001)
while not event.is_set():
with lock:
if len(position) == 0:
position = [self.top + 1]
self.stdscr.addstr(position[0], int(
name), next(message), attr)
length = random.randint(1, 15)
if position[0] < self.bottom - 1:
position.insert(0, position[0] + 1)
self.stdscr.addstr(position[0], int(
name), next(message), attr)
if (len(position) > length or position[0] == self.bottom - 1) and len(position) > 0:
self.stdscr.addstr(position.pop(), int(name), " ")
self.stdscr.refresh()
time.sleep(0.05)
def main(stdscr):
te = playground(stdscr)
for i in range(te.left + 1, te.right - 1):
temp = threading.Thread(target=te.matrix, name=i)
temp.start()
if __name__ == "__main__":
curses.wrapper(main)