Skip to content

Instantly share code, notes, and snippets.

@GongT
Last active September 16, 2019 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GongT/a4ffee2bd74eac73994ad75137916cbe to your computer and use it in GitHub Desktop.
Save GongT/a4ffee2bd74eac73994ad75137916cbe to your computer and use it in GitHub Desktop.
color in shell
#!/bin/bash
# rgb R G B
# 0 <= RGB <= 5
function rgb() {
local R=$1 G=$2 B=$3
echo -n $(( $R * 36 + $G * 6 + $B + 16 ))
}
#!/bin/bash
function test1() {
local R G B
for R in 0 1 2 3 4 5 ; do
for G in 0 1 2 3 4 5 ; do
for B in 0 1 2 3 4 5 ; do
printf "\e[48;5;$(rgb $R $G $B)m %3s " $(rgb $R $G $B)
done
echo -ne "\e[0m\n"
done
echo -ne "\e[0m\n"
done
}
function p2() {
local CARR=(00 5f 87 af d7 ff)
echo -ne "\e[48;5;$(rgb $R $G $B)m \e[0m"
printf " - %3s " $(rgb $R $G $B)
echo -e "($R, $G, $B) #${CARR[$R]}${CARR[$G]}${CARR[$B]}"
}
function test2() {
local I=16 R=5 G=0 B=0
local GL=${1-"5"}
local GH=$(( $GL - 1 ))
for G in $(seq 0 $GL) ; do
p2
done
for R in $(seq $GH -1 0) ; do
p2
done
for B in $(seq 0 $GL) ; do
p2
done
for G in $(seq $GH -1 0) ; do
p2
done
for R in $(seq 0 $GL) ; do
p2
done
for B in $(seq $GH -1 0) ; do
p2
done
}
@GongT
Copy link
Author

GongT commented Sep 16, 2019

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment