This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.py
executable file
·110 lines (103 loc) · 1.89 KB
/
colors.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
#!/usr/bin/env python3
# display terminal colors
# by katacarbix
# do whatever you want
import sys
import random
patterns = {
'swatches': [
'',
' tttttt ',
' tttttt ',
' bbbtttttt ',
' bbbbbb ',
' bbbbbb ',
''
],
'swatches2': [
'',
' tttttt ',
' tttttt ',
' tttbbbbbb ',
' bbbbbb ',
' bbbbbb ',
''
],
'squares': [
'',
'tttttttttt',
'ttbbbbbbtt',
'ttbbbbbbtt',
'ttbbbbbbtt',
'tttttttttt',
''
],
'mini': [
'',
'tt',
''
],
'small': [
'',
'tttt',
'bbbb',
''
],
'invaders': [
'',
' tt tt ',
' tt tt ',
' tttttttttttttt ',
' tttt tttttt tttt ',
'tttttttttttttttttttttt ',
'tt tttttttttttttt tt ',
'tt tt tt tt ',
' tttt tttt ',
'',
' bb bb ',
' bb bb ',
' bbbbbbbbbbbbbb ',
' bbbb bbbbbb bbbb ',
'bbbbbbbbbbbbbbbbbbbbbb ',
'bb bbbbbbbbbbbbbb bb ',
'bb bb bb bb ',
' bbbb bbbb '
''
],
'creepers': [
'',
' tttt tttt ',
' tttt tttt ',
' tttt ',
' tttttttt ',
' tttttttt ',
' tt tt ',
''
]
}
block = "\u2588" # block char code
reset = "\033[0m" # reset color sequence
def color(c): # color escape sequence
return "\033[" + str(30+c) + "m"
def draw(key):
for line in patterns[key]:
for top in range(8):
bottom = top + 60
for char in line:
if char == ' ':
print(char, end='')
elif char == 't':
print(color(top) + block, end='')
elif char == 'b':
print(color(bottom) + block, end='')
else:
print(color(top) + char, end='')
print(reset)
if __name__ == "__main__":
if len(sys.argv) < 2:
draw(random.choice(list(patterns.keys())))
else:
try:
draw(str(sys.argv[1]))
except KeyError:
print("Unknown pattern: '" + str(sys.argv[1]) + "'")