#!/bin/sh -u # parabola loop with display X,Y made positive to fit on terminal screen # # 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 # To make this loop work for terminal graphics output, both X and Y # have to be positive and have to fit inside the terminal window. # We adjust x to get "dispx" and y to get "dispy". # # 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. # # Y adjust for "dispy": # We assume that the terminal window has 41 lines (rows). (A better # version of this script would use "tput lines" to find the real # number.) Our internal value of Y goes from -20 to +20. To make this # range from 0 to 41, we add 20 (the value of num). # # X adjust for "dispx": # We assume that the terminal window has 80 columns. (A better version # of this script would use "tput cols" to find the real number.) Our # internal value of X (Y squared) goes between 0 and 400. To make this # range from 0 to 80, we multiply by 80 then divide by 20 squared (num # squared). Do multiplication before division in integer math! # 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 echo "y is $y, x is $x, dispy is $dispy, dispx is $dispx" let y=y+1 sleep 0.1 done