Skip to content

Instantly share code, notes, and snippets.

@0xAether
Created July 30, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xAether/3211297 to your computer and use it in GitHub Desktop.
Save 0xAether/3211297 to your computer and use it in GitHub Desktop.
Prints the triforce
#!/usr/bin/env bash
#
# Triforce
# By: Aaron
# Date: July 30, 2012
#
# This script will only accept one argument that should be a number greater than or equal to 11.
# It will print a triforce symbol with the base being as wide as the nearest odd number to the one provided.
#
# Screenshot: http://newroman.net/permalink/triforce.png
#
if [ $# != 1 ] || [ $1 -lt 11 ]
then
printf "This script can only accept one argument. That should be a number that is greater than or equal to 11\n"
exit 1
fi
if [ `expr $1 % 2` -eq 0 ]
then
base=`expr $1 - 1`
else
base=$1
fi
check=`expr $base - 1`
check=`expr $base / 2`
if [ `expr $check % 2` -eq 0 ]
then
base=`expr $base + 2`
fi
ospaces=`expr $(($base - 1)) / 2`
tbase=$ospaces
stars=-1
counter=0
tlimit=`expr $(($tbase + 1)) / 2`
while [ $counter -lt $tlimit ]
do
spacecounter=0
while [ $spacecounter -lt $ospaces ]
do
printf " "
spacecounter=`expr $spacecounter + 1`
done
starcounter=0
stars=`expr $stars + 2`
while [ $starcounter -lt $stars ]
do
printf "*"
starcounter=`expr $starcounter + 1`
done
printf "\n"
counter=`expr $counter + 1`
ospaces=`expr $ospaces - 1`
ispaces=$stars
done
stars=-1
while [ $ospaces -ge 0 ] && [ $ispaces -ge 1 ]
do
spacecounter=0
while [ $spacecounter -lt $ospaces ]
do
printf " "
spacecounter=`expr $spacecounter + 1`
done
ospaces=`expr $ospaces - 1`
stars=`expr $stars + 2`
starcounter=0
while [ $starcounter -lt $stars ]
do
printf "*"
starcounter=`expr $starcounter + 1`
done
spacecounter=0
while [ $spacecounter -lt $ispaces ]
do
printf " "
spacecounter=`expr $spacecounter + 1`
done
ispaces=`expr $ispaces - 2`
starcounter=0
while [ $starcounter -lt $stars ]
do
printf "*"
starcounter=`expr $starcounter + 1`
done
printf "\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment