Last active
September 16, 2019 16:01
-
-
Save GongT/a4ffee2bd74eac73994ad75137916cbe to your computer and use it in GitHub Desktop.
color in shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 )) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} |
Author
GongT
commented
Sep 16, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment