jsonfmt.py: Don't sort the JSON, use the new -s/--sort option for that
[sunny256-utils.git] / 24-bit-color.sh
blobf407258f1bcac69683edcc373c239ffee9931a79
1 #!/bin/bash
2 # This file was originally taken from iterm2 https://github.com/gnachman/iTerm2/blob/master/tests/24-bit-color.sh
4 # This file echoes a bunch of 24-bit color codes
5 # to the terminal to demonstrate its functionality.
6 # The foreground escape sequence is ^[38;2;<r>;<g>;<b>m
7 # The background escape sequence is ^[48;2;<r>;<g>;<b>m
8 # <r> <g> <b> range from 0 to 255 inclusive.
9 # The escape sequence ^[0m returns output to default
11 setBackgroundColor()
13 #printf '\x1bPtmux;\x1b\x1b[48;2;%s;%s;%sm' $1 $2 $3
14 printf '\x1b[48;2;%s;%s;%sm' $1 $2 $3
17 resetOutput()
19 echo -en "\x1b[0m\n"
22 # Gives a color $1/255 % along HSV
23 # Who knows what happens when $1 is outside 0-255
24 # Echoes "$red $green $blue" where
25 # $red $green and $blue are integers
26 # ranging between 0 and 255 inclusive
27 rainbowColor()
29 let h=$1/43
30 let f=$1-43*$h
31 let t=$f*255/43
32 let q=255-t
34 if [ $h -eq 0 ]
35 then
36 echo "255 $t 0"
37 elif [ $h -eq 1 ]
38 then
39 echo "$q 255 0"
40 elif [ $h -eq 2 ]
41 then
42 echo "0 255 $t"
43 elif [ $h -eq 3 ]
44 then
45 echo "0 $q 255"
46 elif [ $h -eq 4 ]
47 then
48 echo "$t 0 255"
49 elif [ $h -eq 5 ]
50 then
51 echo "255 0 $q"
52 else
53 # execution should never reach here
54 echo "0 0 0"
58 for i in `seq 0 127`; do
59 setBackgroundColor $i 0 0
60 echo -en " "
61 done
62 resetOutput
63 for i in `seq 255 -1 128`; do
64 setBackgroundColor $i 0 0
65 echo -en " "
66 done
67 resetOutput
69 for i in `seq 0 127`; do
70 setBackgroundColor 0 $i 0
71 echo -n " "
72 done
73 resetOutput
74 for i in `seq 255 -1 128`; do
75 setBackgroundColor 0 $i 0
76 echo -n " "
77 done
78 resetOutput
80 for i in `seq 0 127`; do
81 setBackgroundColor 0 0 $i
82 echo -n " "
83 done
84 resetOutput
85 for i in `seq 255 -1 128`; do
86 setBackgroundColor 0 0 $i
87 echo -n " "
88 done
89 resetOutput
91 for i in `seq 0 127`; do
92 setBackgroundColor `rainbowColor $i`
93 echo -n " "
94 done
95 resetOutput
96 for i in `seq 255 -1 128`; do
97 setBackgroundColor `rainbowColor $i`
98 echo -n " "
99 done
100 resetOutput