Sha256: 7afbc618128dadaddfdab03dad215892dafa908b1a139a0833331e3914109e03

Contents?: true

Size: 1.84 KB

Versions: 58

Compression:

Stored size: 1.84 KB

Contents

#!/bin/bash
#
#   This file echoes a bunch of 24-bit color codes
#   to the terminal to demonstrate its functionality.
#   The foreground escape sequence is ^[38;2;<r>;<g>;<b>m
#   The background escape sequence is ^[48;2;<r>;<g>;<b>m
#   <r> <g> <b> range from 0 to 255 inclusive.
#   The escape sequence ^[0m returns output to default

setBackgroundColor()
{
    echo -en "\x1b[48;2;$1;$2;$3""m"
}

resetOutput()
{
    echo -en "\x1b[0m\n"
}

# Gives a color $1/255 % along HSV
# Who knows what happens when $1 is outside 0-255
# Echoes "$red $green $blue" where
# $red $green and $blue are integers
# ranging between 0 and 255 inclusive
rainbowColor()
{
    let h=$1/43
    let f=$1-43*$h
    let t=$f*255/43
    let 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
}

for i in `seq 0 127`; do
    setBackgroundColor $i 0 0
    echo -en " "
done
resetOutput
for i in `seq 255 128`; do
    setBackgroundColor $i 0 0
    echo -en " "
done
resetOutput

for i in `seq 0 127`; do
    setBackgroundColor 0 $i 0
    echo -n " "
done
resetOutput
for i in `seq 255 128`; do
    setBackgroundColor 0 $i 0
    echo -n " "
done
resetOutput

for i in `seq 0 127`; do
    setBackgroundColor 0 0 $i
    echo -n " "
done
resetOutput
for i in `seq 255 128`; do
    setBackgroundColor 0 0 $i
    echo -n " "
done
resetOutput

for i in `seq 0 127`; do
    setBackgroundColor `rainbowColor $i`
    echo -n " "
done
resetOutput
for i in `seq 255 128`; do
    setBackgroundColor `rainbowColor $i`
    echo -n " "
done
resetOutput

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
vedeu-0.4.31 examples/colour_support.sh
vedeu-0.4.30 examples/colour_support.sh
vedeu-0.4.29 examples/colour_support.sh
vedeu-0.4.28 examples/colour_support.sh
vedeu-0.4.27 examples/colour_support.sh
vedeu-0.4.26 examples/colour_support.sh
vedeu-0.4.25 examples/colour_support.sh
vedeu-0.4.24 examples/colour_support.sh
vedeu-0.4.23 examples/colour_support.sh
vedeu-0.4.22 examples/colour_support.sh
vedeu-0.4.21 examples/colour_support.sh
vedeu-0.4.20 examples/colour_support.sh
vedeu-0.4.19 examples/colour_support.sh
vedeu-0.4.18 examples/colour_support.sh
vedeu-0.4.17 examples/colour_support.sh
vedeu-0.4.16 examples/colour_support.sh
vedeu-0.4.15 examples/colour_support.sh
vedeu-0.4.14 examples/colour_support.sh
vedeu-0.4.13 examples/colour_support.sh
vedeu-0.4.12 examples/colour_support.sh