patched rainbow text
This commit is contained in:
parent
ff9e852444
commit
de96d1f38e
@ -11,31 +11,38 @@ NC='\033[0m'
|
|||||||
|
|
||||||
render_gradient_string() {
|
render_gradient_string() {
|
||||||
local input="$1"
|
local input="$1"
|
||||||
local regex='#([0-9a-fA-F]{6})(.)'
|
local regex='^#([0-9a-fA-F]{6})(.)'
|
||||||
while [[ "$input" =~ $regex ]]; do
|
local rest
|
||||||
color="${BASH_REMATCH[1]}"
|
|
||||||
char="${BASH_REMATCH[2]}"
|
while [[ -n "$input" ]]; do
|
||||||
r=$((16#${color:0:2}))
|
if [[ "$input" =~ $regex ]]; then
|
||||||
g=$((16#${color:2:2}))
|
color="${BASH_REMATCH[1]}"
|
||||||
b=$((16#${color:4:2}))
|
char="${BASH_REMATCH[2]}"
|
||||||
printf "\e[38;2;%d;%d;%dm%s" "$r" "$g" "$b" "$char"
|
r=$((16#${color:0:2}))
|
||||||
input="${input#"#${color}${char}"}"
|
g=$((16#${color:2:2}))
|
||||||
|
b=$((16#${color:4:2}))
|
||||||
|
printf "\e[38;2;%d;%d;%dm%s" "$r" "$g" "$b" "$char"
|
||||||
|
input="${input:9}" # strip exactly 7 (color) + 1 (char) = 8 chars, plus 1 for #
|
||||||
|
else
|
||||||
|
printf "%s" "${input:0:1}"
|
||||||
|
input="${input:1}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "\e[0m"
|
echo -e "\e[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rainbowize_text() {
|
rainbowize_text() {
|
||||||
local text="$1"
|
local text="$1"
|
||||||
local freq=0.15
|
local freq=0.15
|
||||||
local i=0
|
local i=0
|
||||||
local output=""
|
|
||||||
local pi=3.14159265
|
local pi=3.14159265
|
||||||
|
local output=""
|
||||||
|
|
||||||
clamp() {
|
clamp() {
|
||||||
local val="$1"
|
local val="$1" min="$2" max="$3"
|
||||||
local min="$2"
|
|
||||||
local max="$3"
|
|
||||||
if (( val < min )); then echo "$min"
|
if (( val < min )); then echo "$min"
|
||||||
elif (( val > max )); then echo "$max"
|
elif (( val > max )); then echo "$max"
|
||||||
else echo "$val"
|
else echo "$val"
|
||||||
@ -45,6 +52,7 @@ rainbowize_text() {
|
|||||||
while IFS= read -r line || [ -n "$line" ]; do
|
while IFS= read -r line || [ -n "$line" ]; do
|
||||||
for (( j=0; j<${#line}; j++ )); do
|
for (( j=0; j<${#line}; j++ )); do
|
||||||
char="${line:$j:1}"
|
char="${line:$j:1}"
|
||||||
|
|
||||||
r=$(awk -v i="$i" -v f="$freq" 'BEGIN { printf("%d", 127 * (sin(f*i + 0) + 1)) }')
|
r=$(awk -v i="$i" -v f="$freq" 'BEGIN { printf("%d", 127 * (sin(f*i + 0) + 1)) }')
|
||||||
g=$(awk -v i="$i" -v f="$freq" 'BEGIN { printf("%d", 127 * (sin(f*i + 2*3.1415/3) + 1)) }')
|
g=$(awk -v i="$i" -v f="$freq" 'BEGIN { printf("%d", 127 * (sin(f*i + 2*3.1415/3) + 1)) }')
|
||||||
b=$(awk -v i="$i" -v f="$freq" 'BEGIN { printf("%d", 127 * (sin(f*i + 4*3.1415/3) + 1)) }')
|
b=$(awk -v i="$i" -v f="$freq" 'BEGIN { printf("%d", 127 * (sin(f*i + 4*3.1415/3) + 1)) }')
|
||||||
@ -53,14 +61,10 @@ rainbowize_text() {
|
|||||||
g=$(clamp "$g" 50 230)
|
g=$(clamp "$g" 50 230)
|
||||||
b=$(clamp "$b" 50 230)
|
b=$(clamp "$b" 50 230)
|
||||||
|
|
||||||
rh=$(printf "%02x" "$r")
|
output+="#$(printf '%02x%02x%02x' "$r" "$g" "$b")$char"
|
||||||
gh=$(printf "%02x" "$g")
|
|
||||||
bh=$(printf "%02x" "$b")
|
|
||||||
|
|
||||||
output+="#${rh}${gh}${bh}${char}"
|
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
output+=$'\n' # Important!
|
output+=$'\n'
|
||||||
done <<< "$text"
|
done <<< "$text"
|
||||||
|
|
||||||
echo -ne "$output"
|
echo -ne "$output"
|
||||||
@ -69,6 +73,7 @@ rainbowize_text() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# rainbowize_text() {
|
# rainbowize_text() {
|
||||||
# local text="$1"
|
# local text="$1"
|
||||||
# local freq=0.15
|
# local freq=0.15
|
||||||
|
Loading…
x
Reference in New Issue
Block a user