Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created April 22, 2012 15:14
Show Gist options
  • Save c00kiemon5ter/2464574 to your computer and use it in GitHub Desktop.
Save c00kiemon5ter/2464574 to your computer and use it in GitHub Desktop.
fill your terminal with colored pipes/tubes
#!/bin/bash -e
declare -i f=75 s=13 r=5000 t=0 c=1 n=0 l=0
declare -i x=$((w/2)) y=$((h/2))
declare -ar v=( [00]="\x83" [01]="\x8f" [03]="\x93"
[10]="\x9b" [11]="\x81" [12]="\x93"
[21]="\x97" [22]="\x83" [23]="\x9b"
[30]="\x97" [32]="\x8f" [33]="\x81"
)
trap "clear; tput rmcup; tput cnorm" EXIT
tput smcup; tput reset; tput civis
while ! read -t0.0$((1000/$f)) -n1; do
# update boundaries
declare -i w=$(tput cols) h=$(tput lines)
# set new position:
(($l%2)) && ((x+=($l==1)?1:-1)) || ((y+=($l==2)?1:-1))
# loop on edges (change color on loop)
((c=($x>$w || $x<0 || $y>$h || $y<0)?($RANDOM%7-1):$c))
((x=($x>$w)?0:(($x<0)?$w:$x)))
((y=($y>$h)?0:(($y<0)?$h:$y)))
# new random direction
((n=$RANDOM%$s-1))
((n=($n>1||$n==0)?$l:$l+$n))
((n=($n<0)?3:$n%4))
# print or clear
tput cup $y $x
echo -ne "\033[1;3${c}m\xe2\x94${v[$l$n]}"
(($t>$r)) && { tput reset; tput civis; t=0; } || ((t++))
l=$n
done
@c00kiemon5ter
Copy link
Author

original found here
small changes applied

Copy link

ghost commented Apr 22, 2012

Wait, why did you set -e? It is not working with it (or i'm missing something).

@c00kiemon5ter
Copy link
Author

I was testing, -e will exit when an error occures. it works the way it is now, needs some work though. the trap doesn't always run (^C may break this). also I've removed the arguments parsing for now.
mostly playing around :) this should also work when resizing the terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment