Created
April 22, 2012 15:14
-
-
Save c00kiemon5ter/2464574 to your computer and use it in GitHub Desktop.
fill your terminal with colored pipes/tubes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was testing,
-e
will exit when an error occures. it works the way it is now, needs some work though. thetrap
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