#!/bin/bash -u # $0 [ type [ word [ time ] ] ] # type is 'solid' or 'clearing' # Draw a circle on the terminal screen using cursor control. # Put out the word or a "*" if no word. # time is time allowed to draw one complete sine # (we draw one forward and then one backward) # -Ian! D. Allen - idallen@idallen.ca - www.idallen.com PATH=/bin:/usr/bin ; export PATH LC_ALL=C ; export LC_ALL # no internationalization in this script LANG=C ; export LANG umask 022 type=${1-'clearing'} word=${2-'*'} time=${3-'2'} ColourSwitch () { # this fails if terminal doesn't do colours; let it pass tput setaf ${colours[$colour]} # || exit $? colour=$(( ( colour + 1 ) % ${#colours[*]} )) } case "$type" in clearing ) el=$( tput el ) || exit $? el1=$( tput el1 ) || exit $? ;; solid ) el= el1= ;; * ) echo 1>&2 "$0: unknown type '$type' must be solid or clearing" exit 1 ;; esac ss=( $(stty size) ) || exit $? rows=${ss[0]} cols=${ss[1]} # divide the time by the number of columns to find colsleep colsleep=$( dc -e "2 k $time $cols / p" ) width=$cols margin=$(( width - ${#word} )) or=$(( rows / 2 )) oc=$(( cols / 2 )) colours=( $( seq 1 6 | sort -R ) ) colour=0 r=$rows # echo "colours ${colours[*]}" piby4=$( echo 'scale=10 ; a(1)' | bc -l ) shrink=0.945 for (( i=0; i <= cols; i++ )) ; do y=$( echo "scale=10; x = $or + $shrink * $or * s(8*$i/$cols*$piby4); scale=0; x / 1" | bc -l ) tput cup $y $i || exit $? if [ $i -ge $margin ] ; then echo -n "$el*" else echo -n "$el$word" fi ColourSwitch sleep $colsleep done for (( i=cols; i >= 0; i-- )) ; do y=$( echo "scale=10; x = $or - $shrink * $or * s(8*$i/$cols*$piby4); scale=0; x / 1" | bc -l ) tput cup $y $i || exit $? if [ $i -ge $margin ] ; then echo -n "*" else echo -n "$word" fi ColourSwitch sleep $colsleep done tput sgr0 || exit $? tput cup 0 0 || exit $?