Advertisement
ananas

Terminal screensaver

Dec 6th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. declare -i  f=75 s=13 r=2000 t=0 c=1 n=0 l=0
  3. declare -ir w=$(tput cols) h=$(tput lines)
  4. declare -i  x=$((w/2)) y=$((h/2))
  5. declare -ar v=(    [00]="\x83" [01]="\x8f" [03]="\x93"
  6.         [10]="\x9b" [11]="\x81" [12]="\x93"
  7.         [21]="\x97" [22]="\x83" [23]="\x9b"
  8.         [30]="\x97" [32]="\x8f" [33]="\x81" )
  9.  
  10. OPTIND=1
  11. while getopts "f:s:r:h" arg; do
  12.     case $arg in
  13.     f)    ((f=($OPTARG>19 && $OPTARG<101)?$OPTARG:$f));;
  14.     s)    ((s=($OPTARG>4  && $OPTARG<16 )?$OPTARG:$s));;
  15.     r)    ((r=($OPTARG>0)?$OPTARG:$r));;
  16.     h)    echo -e "Usage: pipes [OPTION]..."
  17.         echo -e "Animated pipes terminal screensaver.\n"
  18.         echo -e "  -f [20-100]\tframerate (D=75)."
  19.         echo -e "  -s [5-15]\tprobability of a straight fitting (D=13)."
  20.         echo -e "  -r LIMIT\treset after x characters (D=2000)."
  21.         echo -e "  -h\t\thelp (this screen).\n"
  22.         exit 0;;
  23.     esac
  24. done
  25.  
  26. tput smcup
  27. tput reset
  28. tput civis
  29. while ! read -t0.0$((1000/$f)) -n1; do
  30.     # New position:
  31.     (($l%2))    && ((x+=($l==1)?1:-1))
  32.     ((!($l%2))) && ((y+=($l==2)?1:-1))
  33.  
  34.     # Loop on edges (change color on loop):
  35.     ((c=($x>$w || $x<0 || $y>$h || $y<0)?($RANDOM%7):$c))
  36.     ((x=($x>$w)?0:(($x<0)?$w:$x)))
  37.     ((y=($y>$h)?0:(($y<0)?$h:$y)))
  38.  
  39.     # New random direction:
  40.     ((n=$RANDOM%$s-1))
  41.     ((n=($n>1||$n==0)?$l:$l+$n))
  42.     ((n=($n<0)?3:$n%4))
  43.  
  44.     # Print:
  45.     tput cup $y $x
  46.     echo -ne "\033[1;3${c}m\xe2\x94${v[$l$n]}"
  47.     (($t>$r)) && tput reset && tput civis && t=0 || ((t++))
  48.     l=$n
  49. done
  50. tput rmcup
  51. tput reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement