URI:
       tpipes - scripts - various script and utils
  HTML git clone git://z3bra.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
       tpipes (1613B)
       ---
            1 #!/bin/sh
            2 
            3 declare -i f=75 s=13 r=2000 t=0 c=1 n=0 l=0
            4 declare -ir w=$(tput cols) h=$(tput lines)
            5 declare -i x=$((w/2)) y=$((h/2))
            6 declare -ar v=( [00]="\x83" [01]="\x8f" [03]="\x93"
            7         [10]="\x9b" [11]="\x81" [12]="\x93"
            8         [21]="\x97" [22]="\x83" [23]="\x9b"
            9         [30]="\x97" [32]="\x8f" [33]="\x81" )
           10 
           11 OPTIND=1
           12 while getopts "cf:s:r:h" arg; do
           13 case $arg in
           14     c) COLOR=true;;
           15     f) ((f=($OPTARG>19 && $OPTARG<101)?$OPTARG:$f));;
           16     s) ((s=($OPTARG>4 && $OPTARG<16 )?$OPTARG:$s));;
           17     r) ((r=($OPTARG>0)?$OPTARG:$r));;
           18     h) echo -e "Usage: pipes [OPTION]..."
           19         echo -e "Animated pipes terminal screensaver.\n"
           20         echo -e " -c\t\tUse random colors for pipes"
           21         echo -e " -f [20-100]\tframerate (D=75)."
           22         echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
           23         echo -e " -r LIMIT\treset after x characters (D=2000)."
           24         echo -e " -h\t\thelp (this screen).\n"
           25         exit 0;;
           26     esac
           27 done
           28 
           29 tput smcup
           30 tput reset
           31 tput civis
           32 while ! read -t0.0$((1000/$f)) -n1; do
           33     # New position:
           34     (($l%2)) && ((x+=($l==1)?1:-1))
           35     ((!($l%2))) && ((y+=($l==2)?1:-1))
           36 
           37     # Loop on edges (change color on loop):
           38     ((c=($x>$w || $x<0 || $y>$h || $y<0)?($RANDOM%7-1):$c))
           39     ((x=($x>$w)?0:(($x<0)?$w:$x)))
           40     ((y=($y>$h)?0:(($y<0)?$h:$y)))
           41 
           42     # New random direction:
           43     ((n=$RANDOM%$s-1))
           44     ((n=($n>1||$n==0)?$l:$l+$n))
           45     ((n=($n<0)?3:$n%4))
           46 
           47     # Print:
           48     tput cup $y $x
           49     test "$COLOR" = "true" && echo -ne "\033[1;3${c}m"
           50     echo -ne "\xe2\x94${v[$l$n]}"
           51     (($t>$r)) && tput reset && tput civis && t=0 || ((t++))
           52     l=$n
           53 done
           54 tput rmcup