-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.py
executable file
·75 lines (62 loc) · 1.24 KB
/
color.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
#!/bin/python
def ascii_color():
'''
tty环境会乱码
'''
for i in range(0, 11):
for j in range(0, 10):
n = 10*i + j
if (n >= 108): break
print("\033[{}m{}\033[m ".format(n, n), end='')
print()
def setBG(r:int, g:int, b:int):
print('\033[48:2:{}:{}:{}m'.format(r, g, b), end=' ')
def reset():
print('\033[0m', end='')
def rainbowColor(c:int):
h = c//43
f = c - 43*h
t = f * 255//43
q = 255 - t
if (h == 0):
return 255, t, 0
elif (h == 1):
return q, 255, 0
elif (h == 2):
return 0, 255, t
elif (h == 3):
return 0, q, 255
elif (h == 4):
return t, 0, 255
elif (h == 5):
return 255, 0, q
else:
return 0, 0, 0
for i in range(0, 127):
setBG(i, 0, 0)
reset()
print()
for i in range(0, 127):
setBG(0, i, 0)
reset()
print()
for i in range(0, 127):
setBG(0, 0, i)
reset()
print()
for i in range(255, 128):
setBG(i, 0, 0)
reset()
for i in range(255, 128):
setBG(0, i, 0)
reset()
for i in range(255, 128):
setBG(0, 0, i)
reset()
for i in range(0, 127):
setBG(*rainbowColor(i))
reset()
print()
for i in range(255, 128):
setBG(*rainbowColor(i))
reset()