Skip to content

Commit

Permalink
Add -c option to manually specify colours.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
parkercoates committed Sep 25, 2015
1 parent cfa757e commit 8d4b46a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
25 changes: 25 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ Custom pipe, for example: ``-t cMAYFORCEBWITHYOU``.
.. figure:: doc/pipes.tc.png

``-c [0-7]``
------------

Color of pipes, can be used more than once (D=1 2 3 4 5 6 7 0).

Numbers are terminal color numbers. Traditionally typical values are:

+---+------------+
| 0 | background |
+---+------------+
| 1 | red |
+---+------------+
| 2 | green |
+---+------------+
| 3 | yellow |
+---+------------+
| 4 | blue |
+---+------------+
| 5 | magenta |
+---+------------+
| 6 | cyan |
+---+------------+
| 7 | foreground |
+---+------------+

``-f [20-100]``
---------------

Expand Down
11 changes: 8 additions & 3 deletions pipes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NOCOLOR=0
NOEDGECHANGE=0

OPTIND=1
while getopts "p:t:f:s:r:RBCEhv" arg; do
while getopts "p:t:c:f:s:r:RBCEhv" arg; do
case $arg in
p) ((p=(OPTARG>0)?OPTARG:p));;
t)
Expand All @@ -50,6 +50,7 @@ case $arg in
((OPTARG>=0 && OPTARG<${#sets[@]})) && V+=($OPTARG)
fi
;;
c) [[ $OPTARG =~ ^[0-7]$ ]] && C+=($OPTARG);;
f) ((f=(OPTARG>19 && OPTARG<101)?OPTARG:f));;
s) ((s=(OPTARG>4 && OPTARG<16 )?OPTARG:s));;
r) ((r=(OPTARG>=0)?OPTARG:r));;
Expand All @@ -61,6 +62,7 @@ case $arg in
echo -e "Animated pipes terminal screensaver.\n"
echo -e " -p [1-]\tnumber of pipes (D=1)."
echo -e " -t [0-$((${#sets[@]} - 1))]\ttype of pipes, can be used more than once (D=0)."
echo -e " -c [0-7]\tcolor of pipes, can be used more than once (D=1 2 3 4 5 6 7 0)."
echo -e " -t c[16 chars]\tcustom type of pipes."
echo -e " -f [20-100]\tframerate (D=75)."
echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
Expand All @@ -79,6 +81,7 @@ done

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

cleanup() {
# clear up standard input
Expand All @@ -100,7 +103,9 @@ trap 'break 2' INT
resize

for (( i=1; i<=p; i++ )); do
c[i]=$((i%8)) n[i]=0 l[i]=0
c[i]=${C[$(((i-1)%${#C[@]}))]}
n[i]=0
l[i]=0
((x[i]=RNDSTART==1?RANDOM*w/32768:w/2))
((y[i]=RNDSTART==1?RANDOM*h/32768:h/2))
v[i]=${V[$(((i-1)%${#V[@]}))]}
Expand All @@ -117,7 +122,7 @@ while REPLY=; read -t 0.0$((1000/f)) -n 1 2>/dev/null; [[ -z $REPLY ]] ; do
((${l[i]}%2)) && ((x[i]+=-${l[i]}+2,1)) || ((y[i]+=${l[i]}-1))

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

Expand Down

0 comments on commit 8d4b46a

Please sign in to comment.