random

- collection of un-sorted bollocks
git clone git://git.acid.vegas/random.git
Log | Files | Refs | Archive

wave (1816B)

      1 #!/bin/bash
      2 # wave egenrator - developed by acidvegas (https://git.acid.vegas)
      3 
      4 random_color() {
      5     echo $((RANDOM % 256))
      6 }
      7 
      8 rainbow_color() {
      9     local index="$1"
     10     local colors=("196" "202" "208" "214" "220" "226" "190" "154" "118" "82" "46" "47" "48" "49" "50" "51" "45" "39" "33" "27" "21" "57" "93" "129" "165" "201")
     11     echo "${colors[index % ${#colors[@]}]}"
     12 }
     13 
     14 print_wave() {
     15     local chars="$1"
     16     local len="$2"
     17     local delay="$3"
     18     local color_mode="$4"
     19     local pulse_mode="$5"
     20     local color_idx=0
     21 
     22     while :; do
     23         printf "\r"
     24         for ((i = 0; i < len; i++)); do
     25             if [ "$color_mode" == "rainbow" ]; then
     26                 color="\033[38;5;$(rainbow_color "$color_idx")m"
     27             elif [ "$color_mode" == "chaos" ]; then
     28                 color="\033[38;5;$(random_color)m"
     29             else
     30                 color=""
     31             fi
     32 
     33             char="${chars:i:1}"
     34             if [ "$pulse_mode" == "on" ]; then
     35                 if [ $((RANDOM % 2)) -eq 0 ]; then
     36                     char="${chars:i+1:1}"
     37                 else
     38                     char="${chars:i-1:1}"
     39                 fi
     40             fi
     41 
     42             printf "$color$char"
     43             color_idx=$((color_idx + 1))
     44         done
     45 
     46         sleep "$delay"
     47 
     48         chars="${chars: -1}${chars%?}"
     49     done
     50 }
     51 
     52 length="${1:-15}"
     53 delay="${2:-0.05}"
     54 color_mode="none"
     55 pulse_mode="off"
     56 
     57 if [ "$3" == "-r" ]; then
     58     color_mode="rainbow"
     59 elif [ "$3" == "-c" ]; then
     60     color_mode="chaos"
     61 elif [ "$3" == "-p" ]; then
     62     pulse_mode="on"
     63 fi
     64 
     65 wave_chars="▁▂▃▄▅▆▇█▇▆▅▄▃▂▁"
     66 wave_chars="$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars$wave_chars"
     67 print_wave "$wave_chars" "$length" "$delay" "$color_mode" "$pulse_mode"