Skip to content

Commit d414186

Browse files
committed
Add -c option to manually specify colours.
This behaves pretty much identically to -t. It sets up a pool of available colours, which are assigned to pipes in order and which is chosen from when randomising.
1 parent 521d21c commit d414186

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pipes.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ NOCOLOR=0
3838
NOEDGECHANGE=0
3939

4040
OPTIND=1
41-
while getopts "p:t:f:s:r:RBCEhv" arg; do
41+
while getopts "p:t:c:f:s:r:RBCEhv" arg; do
4242
case $arg in
4343
p) ((p=(OPTARG>0)?OPTARG:p));;
4444
t)
@@ -49,6 +49,7 @@ case $arg in
4949
((OPTARG>=0 && OPTARG<${#sets[@]})) && V+=($OPTARG)
5050
fi
5151
;;
52+
c) ((OPTARG>=0 && OPTARG<8)) && C+=($OPTARG);;
5253
f) ((f=(OPTARG>19 && OPTARG<101)?OPTARG:f));;
5354
s) ((s=(OPTARG>4 && OPTARG<16 )?OPTARG:s));;
5455
r) ((r=(OPTARG>=0)?OPTARG:r));;
@@ -60,6 +61,7 @@ case $arg in
6061
echo -e "Animated pipes terminal screensaver.\n"
6162
echo -e " -p [1-]\tnumber of pipes (D=1)."
6263
echo -e " -t [0-$((${#sets[@]} - 1))]\ttype of pipes, can be used more than once (D=0)."
64+
echo -e " -c [0-7]\tcolor of pipes, can be used more than once (D=1 2 3 4 5 6 7)."
6365
echo -e " -t c[16 chars]\tcustom type of pipes."
6466
echo -e " -f [20-100]\tframerate (D=75)."
6567
echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
@@ -78,6 +80,7 @@ done
7880

7981
# set default values if not by options
8082
((${#V[@]})) || V=(0)
83+
((${#C[@]})) || C=(1 2 3 4 5 6 7)
8184

8285
cleanup() {
8386
# clear up standard input
@@ -99,7 +102,9 @@ trap 'break 2' INT
99102
resize
100103

101104
for (( i=1; i<=p; i++ )); do
102-
c[i]=$((i%8)) n[i]=0 l[i]=0
105+
c[i]=${C[$((i%${#C[@]}))]}
106+
n[i]=0
107+
l[i]=0
103108
((x[i]=RNDSTART==1?RANDOM*w/32768:w/2))
104109
((y[i]=RNDSTART==1?RANDOM*h/32768:h/2))
105110
v[i]=${V[$((i%${#V[@]}))]}
@@ -116,7 +121,7 @@ while REPLY=; read -t 0.0$((1000/f)) -n 1 2>/dev/null; [[ -z $REPLY ]] ; do
116121
((${l[i]}%2)) && ((x[i]+=-${l[i]}+2,1)) || ((y[i]+=${l[i]}-1))
117122

118123
# Loop on edges (change color on loop):
119-
((!NOEDGECHANGE&&(${x[i]}>w||${x[i]}<0||${y[i]}>h||${y[i]}<0))) && ((c[i]=RANDOM%8, v[i]=V[${#V[@]}*RANDOM/M]))
124+
((!NOEDGECHANGE&&(${x[i]}>w||${x[i]}<0||${y[i]}>h||${y[i]}<0))) && ((c[i]=${C[$((RANDOM%${#C[@]}))]}, v[i]=V[${#V[@]}*RANDOM/M]))
120125
((x[i]=(x[i]+w)%w))
121126
((y[i]=(y[i]+h)%h))
122127

0 commit comments

Comments
 (0)