#! /bin/bash

# Displays a series of interlocked diamonds based on an initial width
# specified by the user.

CHARA="*"
CHARB="o"

echo "This program will output interlocked diamonds of $CHARA and $CHARB characters."
echo "What do you want the outermost diamond's width to be?"
answer="-1"
while [ "$answer" -gt "23" ] || [ "$answer" = "" ] || [ "$answer" -lt "0" ]
do
  echo -n "Enter an natural number no greater than 23: "; read answer
done

let "odd=answer%2"
let "half=answer/2"
let "halfplusplus=answer/2+1"
if [ "$odd" -eq "1" ]
  then ilist="`seq 1 $half`
$halfplusplus
`seq $half -1 1`"
  else ilist="`seq 1 $half`
`seq $half -1 1`"
fi

for i in $ilist
do
  let "side=answer/2-i+odd" 
  for ((j=1; j <= side ; j++))
  do
    echo -n " "
  done
  let "middle=(2*i-odd)"
  for ((j=1; j <= middle ; j++))
  do
    let "charsel=(j)%2"
    if [ "$j" -gt "$i" ] && [ "$odd" -eq "0" ]
      then let "charsel=(j+1)%2"
    fi
    if [ "$charsel" -eq "1" ]
    then echo -n "$CHARA"
    else echo -n "$CHARB"
    fi
  done
  for ((j=1; j <= side ; j++))
  do
    echo -n " "
  done
  echo
done
