de linuxmanr4, 4 años han pasado desde su publicación, escrito en Bash.
Enlace corto
http://gw.gd/vQOr
Insertar vínculo
  1. #!/bin/bash
  2. # The author of the original script is unknown to me. The first entry I can
  3. # find was posted at 2010-03-21 09:50:09 on Arch Linux Forums (doesn't mean the
  4. # poster is the author at all):
  5. #
  6. #   https://bbs.archlinux.org/viewtopic.php?pid=728932#p728932
  7. #
  8. # I, Yu-Jie Lin, made a few changes and additions:
  9. #
  10. #   -p, -R, and -C
  11. #
  12. #   Screenshot: http://flic.kr/p/dRnLVj
  13. #   Screencast: http://youtu.be/5XnGSFg_gTk
  14. #
  15. # And push the commits to Gist:
  16. #
  17. #   https://gist.github.com/4689307
  18. #
  19. # I, Devin Samarin, made a few changes and additions:
  20. #
  21. #   -r can be 0 to mean "no limit".
  22. #   Reset cursor visibility after done.
  23. #   Cleanup for those people who want to quit with ^C
  24. #
  25. #   Pushed the changes to https://gist.github.com/4725048
  26.  
  27. p=1
  28. f=75 s=13 r=2000 t=0
  29. w=$(tput cols) h=$(tput lines)
  30. # 0: up, 1: right, 2: down, 3: left
  31. # 00 means going up   , then going up   -> ┃
  32. # 12 means going right, then going down -> ┓
  33. v=( [00]="\x83" [01]="\x8f" [03]="\x93"
  34.     [10]="\x9b" [11]="\x81" [12]="\x93"
  35.     [21]="\x97" [22]="\x83" [23]="\x9b"
  36.     [30]="\x97" [32]="\x8f" [33]="\x81" )
  37. RNDSTART=0
  38. NOCOLOR=0
  39.  
  40. OPTIND=1
  41. while getopts "p:f:s:r:RCh" arg; do
  42. case $arg in
  43.     p) ((p=(OPTARG>0)?OPTARG:p));;
  44.     f) ((f=(OPTARG>19 && OPTARG<101)?OPTARG:f));;
  45.     s) ((s=(OPTARG>4 && OPTARG<16 )?OPTARG:s));;
  46.     r) ((r=(OPTARG>=0)?OPTARG:r));;
  47.     R) RNDSTART=1;;
  48.     C) NOCOLOR=1;;
  49.     h) echo -e "Usage: $(basename $0) [OPTION]..."
  50.         echo -e "Animated pipes terminal screensaver.\n"
  51.         echo -e " -p [1-]\tnumber of pipes (D=1)."
  52.         echo -e " -f [20-100]\tframerate (D=75)."
  53.         echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
  54.         echo -e " -r LIMIT\treset after x characters, 0 if no limit (D=2000)."
  55.         echo -e " -R \t\trandom starting point."
  56.         echo -e " -C \t\tno color."
  57.         echo -e " -h\t\thelp (this screen).\n"
  58.         exit 0;;
  59.     esac
  60. done
  61.  
  62. cleanup() {
  63.     tput rmcup
  64.     tput cnorm
  65.     exit 0
  66. }
  67. trap cleanup SIGHUP SIGINT SIGTERM
  68.  
  69. for (( i=1; i<=p; i++ )); do
  70.     c[i]=$((i%8)) n[i]=0 l[i]=0
  71.     ((x[i]=RNDSTART==1?RANDOM*w/32768:w/2))
  72.     ((y[i]=RNDSTART==1?RANDOM*h/32768:h/2))
  73. done
  74.  
  75. tput smcup
  76. tput reset
  77. tput civis
  78. while ! read -t0.0$((1000/f)) -n1; do
  79.     for (( i=1; i<=p; i++ )); do
  80.         # New position:
  81.         ((${l[i]}%2)) && ((x[i]+=-${l[i]}+2,1)) || ((y[i]+=${l[i]}-1))
  82.  
  83.         # Loop on edges (change color on loop):
  84.         ((${x[i]}>w||${x[i]}<0||${y[i]}>h||${y[i]}<0)) && ((c[i]=RANDOM%8))
  85.         ((x[i]=(x[i]+w)%w))
  86.         ((y[i]=(y[i]+h)%h))
  87.  
  88.         # New random direction:
  89.         ((n[i]=RANDOM%s-1))
  90.         ((n[i]=(${n[i]}>1||${n[i]}==0)?${l[i]}:${l[i]}+${n[i]}))
  91.         ((n[i]=(${n[i]}<0)?3:${n[i]}%4))
  92.  
  93.         # Print:
  94.         tput cup ${y[i]} ${x[i]}
  95.         [[ $NOCOLOR == 0 ]] && echo -ne "\033[1;3${c[i]}m"
  96.         echo -ne "\xe2\x94${v[${l[i]}${n[i]}]}"
  97.         l[i]=${n[i]}
  98.     done
  99.     ((r>0 && t*p>=r)) && tput reset && tput civis && t=0 || ((t++))
  100. done
  101.  
  102. cleanup