colours.sh : Added RGB and rainbow colour gradients

This commit is contained in:
saundersp 2025-04-26 20:07:43 +02:00
parent 8407d3c051
commit 56f5107747

View File

@ -32,3 +32,44 @@ for fgc in {30..37}; do
done done
echo; echo echo; echo
done done
rainbowColor() {
local h=$(($1 / 43))
local f=$(($1 - 43 * h))
local t=$((f * 255 / 43))
local q=$((255 - t))
if [ $h -eq 0 ]
then
echo "255 $t 0"
elif [ $h -eq 1 ]
then
echo "$q 255 0"
elif [ $h -eq 2 ]
then
echo "0 255 $t"
elif [ $h -eq 3 ]
then
echo "0 $q 255"
elif [ $h -eq 4 ]
then
echo "$t 0 255"
elif [ $h -eq 5 ]
then
echo "255 0 $q"
else
# execution should never reach here
echo '0 0 0'
fi
}
rf(){ echo "$1" 0 0; }; gf(){ echo 0 "$1" 0; }; bf(){ echo 0 0 "$1"; }
for f in rf gf bf rainbowColor; do
for s in "$(seq 0 127)" "$(seq 255 -1 128)"; do
for i in $s; do
# shellcheck disable=2183,2046
printf '\x1b[48;2;%s;%s;%sm ' $($f "$i")
done
echo -en "\x1b[0m\n"
done
done