-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectrum
executable file
·64 lines (50 loc) · 1.16 KB
/
spectrum
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
# prints a spectrum of colors
# only work in terminals with 24-bit color support
tt="▇"
#fit to terminal width
st=$(echo "255 / ( $(tput cols) / 6 )" | bc)
#starting values
r=255
g=0
b=0
#print the colors
for ((g=0; g<256; g+=$st)); do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
done
g=255
for ((r=255-$st; r>-1; r-=$st)); do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
done
r=0
for ((b=0+$st; b<256; b+=$st)); do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
done
b=255
for ((g=255-$st; g>-1; g-=$st)); do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
done
g=0
for ((r=0+$st; r<256; r+=$st)); do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
done
r=255
for ((b=255-$st; b>-1; b-=$st)); do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
#cut off if there are more character than can fit in the terminal width
if [ "$cols" -eq "$(tput cols)" ]; then
break
fi
done
r=255
#print extra characters to fill terminal width
while [ "$cols" -lt "$(tput cols)" ]; do
printf "\x1b[38;2;${r};${g};${b}m$tt\x1b[0m"
((cols++))
done
printf "\n"