Advertisement
Guest User

pipes.sh

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