You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pipes.sh 1.5KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  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. OPTIND=1
  10. while getopts "f:s:r:h" arg; do
  11. case $arg in
  12. f) ((f=($OPTARG>19 && $OPTARG<101)?$OPTARG:$f));;
  13. s) ((s=($OPTARG>4 && $OPTARG<16 )?$OPTARG:$s));;
  14. r) ((r=($OPTARG>0)?$OPTARG:$r));;
  15. h) echo -e "Usage: pipes [OPTION]..."
  16. echo -e "Animated pipes terminal screensaver.\n"
  17. echo -e " -f [20-100]\tframerate (D=75)."
  18. echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
  19. echo -e " -r LIMIT\treset after x characters (D=2000)."
  20. echo -e " -h\t\thelp (this screen).\n"
  21. exit 0;;
  22. esac
  23. done
  24. tput smcup
  25. tput reset
  26. tput civis
  27. while ! read -t0.0$((1000/$f)) -n1; do
  28. # New position:
  29. (($l%2)) && ((x+=($l==1)?1:-1))
  30. ((!($l%2))) && ((y+=($l==2)?1:-1))
  31. # Loop on edges (change color on loop):
  32. ((c=($x>$w || $x<0 || $y>$h || $y<0)?($RANDOM%7-1):$c))
  33. ((x=($x>$w)?0:(($x<0)?$w:$x)))
  34. ((y=($y>$h)?0:(($y<0)?$h:$y)))
  35. # New random direction:
  36. ((n=$RANDOM%$s-1))
  37. ((n=($n>1||$n==0)?$l:$l+$n))
  38. ((n=($n<0)?3:$n%4))
  39. # Print:
  40. tput cup $y $x
  41. echo -ne "\033[1;3${c}m\xe2\x94${v[$l$n]}"
  42. (($t>$r)) && tput reset && tput civis && t=0 || ((t++))
  43. l=$n
  44. done
  45. tput rmcup