-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample3.py
68 lines (55 loc) · 1.96 KB
/
example3.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
import random
from colorama import init as colorama_init
from colorama import Style
from colorama import Fore
from ascii_animator import Animator, Animation, Speed
# CHARS = [chr(c) for c in range(11904, 12019)]
# CHARS = [chr(c) for c in range(9600, 9719)]
CHARS1 = [chr(c) for c in range(10240, 10495)]
CHARS2 = [chr(c) for c in range(9600, 9621)]
CHARS = CHARS1 + CHARS2
class Matrix(Animation):
def __init__(self, y_size, x_size):
self.y_size = y_size
self.x_size = x_size
colorama_init()
print(Style.BRIGHT, end='')
self.setup()
self._y_count = 1
self._feed_y_index = 0
self._setup_feed()
def __del__(self):
print(Style.RESET_ALL)
def _setup_feed(self):
self._feed = []
total = int(self.x_size / 3)
for _ in range(total):
self._feed.append([f'{Fore.GREEN}{random.choice(CHARS)}' for _ in range(self.y_size)])
@property
def grid(self):
return self._grid
def setup(self):
self._grid = [[' ' for x in range(self.x_size)] for y in range(self.y_size)]
def cycle(self):
for y in range(self.y_size):
if y not in list(range(self._y_count)):
# allows for rolling list
continue
feed_x_index = 0
for x in range(self.x_size):
if x % 5 == 0:
# create effect for every 5th column
self._grid[y][x] = self._feed[feed_x_index][self._feed_y_index - y]
feed_x_index += 1
self._feed_y_index += 1
if self._feed_y_index == self.y_size:
self._feed_y_index = 0
self._y_count += 1
def cycle2(self):
for y in range(self.y_size):
for x in range(self.x_size):
self._grid[y][x] = random.choice(CHARS)
def main():
Animator(animation=Matrix(25, 100), speed=Speed.SLOW)
if __name__ == '__main__': # pragma: no cover
main()