#!/bin/bash -u # $0 [ type [ word ] ] # type is 'solid' or 'clearing' # Draw a circle on the terminal screen using cursor control. # Put out the word or a "*" if no word. # -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-'solid'} word=${2-'*'} ColourSwitch () { # this fails if terminal doesn't do colours; let it pass tput setaf ${colours[$colour]} # || exit $? colour=$(( colour + 1 )) if [ $colour -ge ${#colours[*]} ] ; then colour=0 fi } el= el1= if [ "$type" = "clearing" ] ; then el=$( tput el ) || exit $? el1=$( tput el1 ) || exit $? fi ss=( $(stty size) ) || exit $? rows=${ss[0]} cols=${ss[1]} width=$cols margin=$(( width - ${#word} )) or=$(( rows / 2 )) oc=$(( cols / 2 )) colours=( $( seq 1 6 | sort -R ) ) colour=0 r=$rows # echo "colours ${colours[*]}" while [ $r -gt 0 ] ; do for (( x=0 ; x <= r ; x++ )) ; do y=$( dc -e "5 k $r $r * $x $x * - v 0.5 + 0 k 2 / p" ) #echo "x $x y $y" ox=$(( oc + x )) oy=$(( or + y )) (( x % 3 == 0 )) && ColourSwitch tput cup $oy $ox || exit $? ; echo -n "$el1$word" done for (( x=r ; x >= 0 ; x-- )) ; do y=$( dc -e "5 k $r $r * $x $x * - v 0.5 + 0 k 2 / p" ) ox=$(( oc + x )) oy=$(( or - y )) (( x % 3 == 0 )) && ColourSwitch tput cup $oy $ox || exit $? ; echo -n "$el1$word" done for (( x=0 ; x <= r ; x++ )) ; do y=$( dc -e "5 k $r $r * $x $x * - v 0.5 + 0 k 2 / p" ) ox=$(( oc - x )) oy=$(( or - y )) (( x % 3 == 0 )) && ColourSwitch if [ "$ox" -lt 0 ] ; then ox=0 fi tput cup $oy $ox || exit $? ; echo -n "$word$el" done for (( x=r ; x >= 0 ; x-- )) ; do y=$( dc -e "5 k $r $r * $x $x * - v 0.5 + 0 k 2 / p" ) ox=$(( oc - x )) if [ "$ox" -lt 0 ] ; then ox=0 fi oy=$(( or + y )) (( x % 3 == 0 )) && ColourSwitch tput cup $oy $ox || exit $? ; echo -n "$word$el" done r=$(( r - 5 )) done tput sgr0 || exit $? tput cup 0 0 || exit $?