#!/bin/sh -u # parabola loop with display X,Y graphed in terminal using tput # # Integer Arithmetic Only! # Shell scripts only deal in integers. The order in which you do # arithmetic matters! let "x=1/80*160" is zero, because "1/80" is zero # in integer artithmetic. let "x=160*1/80" is the right answer "2". # Always do multiplication before division in integer math. # # NOTE: This script fragment is incomplete - it does not follow all # the script guidelines set out in "script_style.txt". It also # contains many "Instructor-Style" comments that you must not use in # your own scripts. See script_style.txt for details. # # -IAN! idallen@idallen.ca PATH=/bin:/usr/bin ; export PATH LC_COLLATE=C ; export LC_COLLATE LANG=C ; export LANG umask 022 # Clear the terminal screen. # tput clear let num=20 let y=-num while [ $y -le $num ] ; do let 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. # let dispy=y+num let dispx=x*80/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 ; echo -n '*' let y=y+1 sleep 0.1 done