#!/bin/bash -u # $0 [ word [ time ] ] # Draw a parabola on the terminal screen using cursor control. # Put out the word or a "*" if no word. # time is total time to draw the parabola, top to bottom # -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 word=${1-'*'} time=${2-'2'} # default 2 seconds ss=( $(stty size) ) || exit $? rows=${ss[0]} cols=${ss[1]} # divide the time by the number of rows to find rowsleep rowsleep=$( dc -e "2 k $time $rows / p" ) width=$cols margin=$(( width - ${#word} )) num=$(( rows / 2 )) y=$(( -num )) while [ $y -le $num ] ; do x=$(( y*y )) # Calculate the display values of X,Y from the program values. # The display values must be non-negative and fit on terminal screen. # dispy=$(( y+num )) dispx=$(( x*width/num/num )) # integer math: do multiplication before division # "tput cup" positions the terminal cursor on the terminal screen. # "tput cup" arguments have Y position first, followed by X... # tput cup $dispy $dispx if [ $dispx -ge $margin ] ; then echo -n "*" else echo -n "$word" fi y=$(( y+1 )) sleep $rowsleep done