#!/bin/bash
#-----------------------------------------------------
# Bashanimation v0.1 
#-----------------------------------------------------
# Script written by Andreas Textor
# Contact: texray@fuckMicrosoft.com 
# Website: http://texray.no-ip.org/
#
# Purpose: A short demo written completely in BASH
#          without any Perl, awk or sed!
#          Bash is powerful!
#-----------------------------------------------------

##############
# Initialize #
##############

# define variables
space=" "
solid="#"
string="          . . . get ready to bash . . . "
size=33
width=$(tput cols)
height=$(tput lines)
IFS=$'\n'; 

# define color constants
BLACK="\033[0;30m"
BLUE="\033[0;34m"
LTBLUE="\033[1;34m"
WHITE="\033[1;37m"
RED="\033[0;31m"
LTRED="\033[1;31m"
GREEN="\033[0;32m"
LTGREEN="\033[1;32m"
PURPLE="\033[0;35m"
LTPURP="\033[1;35m"
YELLOW="\033[1;33m"
BROWN="\033[0;33m"
CYAN="\033[0;36m"
LTCYAN="\033[0;36m"
DKGREY="\033[1;30m"
LTGREY="\033[0;37m"
GRAY=$LTGREY
OFF="\033[0m"

bigtex[0]=" ######## ####### ##    ## "
bigtex[1]="    #     #        ##  ##  "
bigtex[2]="    #     ####      ####   "
bigtex[3]="    #     #        ##  ##  "
bigtex[4]="    #     ######  ##    ## "

phase1[0]="      _____    "
phase1[1]="     / o   \   "
phase1[2]="    <       |  "
phase1[3]="     \/____/   "
phase1[4]="     __|_|_    "
phase1[5]="    /      \   "
phase1[6]="   |  |  |  |  "
phase1[7]="   |_/  /   |  "
phase1[8]="   (___/    |  "
phase1[9]="   |   /\   |  "
phase1[10]="   |  |  |  |  "
phase1[11]="  _|  | _|  |  "
phase1[12]=" (____|(____|  "

phase2[0]="      _____    "
phase2[1]="     / o   \   "
phase2[2]="    <       |  "
phase2[3]="     \/____/   "
phase2[4]="     __|_|_    "
phase2[5]="    /      \   "
phase2[6]="   |  |  |  |  "
phase2[7]="   | _|  |  |  "
phase2[8]="   |(____¦  |  "
phase2[9]="   |   /\   |  "
phase2[10]="   |  |  |  |  "
phase2[11]=" _/  /   \  \  "
phase2[12]="(____|  (____| "

phase3[0]="   _____      "
phase3[1]="  / o o \     "
phase3[2]=" | \___/ |    "
phase3[3]="  \_____/     "
phase3[4]="   _|_|__     "
phase3[5]="  /      \    "
phase3[6]=" |  |  |  |   "
phase3[7]=" |   \  \_|   "
phase3[8]=" |    \___)   "
phase3[9]=" |   /\   |   "
phase3[10]=" |  |  |  |   "
phase3[11]=" |  |_ |  |_  "
phase3[12]=" |____)|____) "

#############
# Functions #
#############

function ScrollText {

for ((i = $width; i>0; i--)); do
 tput cup $2 0
 echo -e "${blankline:1:$i}${1:1:$[$width-$i]}"
done

}

function Bubble {

for ((i = 0; i<10; i++)); do
 tput cup $i 0; echo "$blankline"
done

tput cup 2 0; echo "   ${minusline:1:$[${#1}+2]} "
tput cup 3 0; echo "  |${blankline:1:$[${#1}+2]}|"
tput cup 4 0; echo "  | $1 |"
tput cup 5 0; echo "  |${blankline:1:$[${#1}+2]}|"
tput cup 6 0; echo "   -----  ${minusline:1:$[${#1}-5]} "
tput cup 7 0; echo "        |/"

}

function TopScrollText {

for ((i = 1; i<$2; i++)); do
 tput cup $i 0
 echo -e "$1"
done

}
Quit() {
 clear
 exit 0
}

##################
# Precalculating #
##################

# Trap kill signals 2 and 15
trap Quit 2 15 

# Check for parameters
if [ ! $# -eq 0 ]; then
 echo -en "\nPlease type $0 to start.\n"
 exit 0
fi

# Setup
clear
echo -en "Precalculating Data... Please Wait.\n"

# Generate SpaceString
blankline=$(for((i=1; i<$width; i++));do t="$t "; done; echo "$t")

# Generate MinusString
minusline=$(for((i=1; i<$width; i++));do t="$t-"; done; echo "$t")

# Generate Banner font 
for i in $(banner -w $size "$string" | tr ' ' "$space" | tr '#' "$solid"); do 
 count=$[$count+1]; 
 array[$count]="$i"; 
 while (( ${#array[$count]} < $[$size-10] )); do 
  array[$count]="${array[$count]}$space"
 done
done

# Rotate it
for ((i = 0; i < ${#array[*]}; i++ )); do 
 for ((t = 0; t < $[$size-10]; t++)); do
  spalte[$[$size-10-$t]]="${spalte[$[$size-10-$t]]}${array[$i]:$t:1}"
 done
done

#################
# Splash Screen #
#################

clear

echo -e "$BLUE"

for ((z=5; z>-1; z--)); do
 for ((t=0; t<5000; t++)); do a=1; done;
 TopScrollText "                        ${bigtex[$z]}" $[$z+16]
done
for ((t=0; t<5000; t++)); do a=1; done;
TopScrollText $blankline 15

echo -e "$RED"
ScrollText "        __                                                     __  " 3
ScrollText "       |__|___________________________________________________|__| " 4
ScrollText "          |                                                   |    " 5
ScrollText "        _/                                                     \_  " 6
echo -e "$LTGREEN"
ScrollText "             Welcome to the first BASH graphic demo (AFAIK)        " 7
echo -e "$RED"
ScrollText "        -\                                                     /-  " 8
ScrollText "        __|___________________________________________________|__  " 9
ScrollText "       |__|                                                   |__| " 10
sleep 1
echo -e "$LTGREY"
ScrollText "                               performed by                        " 12
sleep 5

#########################
# Scrolling Banner Text #
#########################

# begin animation
clear
echo -e "$LTGREEN"

for ((t = 0; t < $count; t=t+2)); do
 tput cup 0 0
 for ((i = 0; i < ${#spalte[*]}; i++ )); do
  echo -e "$(echo "${spalte[$i]:$t:$width}")"
 done
done

#################
# Guy Animation #
#################

clear
sleep 1

# walk

echo -e "$LTGREY"
phase=1

for ((i = $width; i>1; i--)); do
 if [ $phase -eq 1 ]; then 
    phase=2;
    for ((t = 0; t<13; t++)); do
        tput cup $[$height-$t-2] 0; echo -e "${blankline:1:$i}${phase1[$[12-$t]]:1:$[$width-$i]}"
    done
 else 
    phase=1; 
    for ((t = 0; t<13; t++)); do
        tput cup $[$height-$t-2] 0; echo -e "${blankline:1:$i}${phase2[$[12-$t]]:1:$[$width-$i]}"
    done
 fi
done

# stand

sleep 1
for ((t = 0; t<13; t++)); do
    tput cup $[$height-$t-2] 0; echo -e " ${phase3[$[12-$t]]}"
done

# talk
sleep 1
Bubble " Why the hell am I so ugly? "; sleep 3
Bubble " Maybe because texray is a lousy artist!"; sleep 3
Bubble "    Blahrg!!!     "; sleep 2

for ((i = 0; i<10; i++)); do
 tput cup $i 0; echo "$blankline"
done


tput cup $[11+($height-25)] 0; echo "    _-_-__      "
tput cup $[12+($height-25)] 0; echo "   / O °  \     "
tput cup $[13+($height-25)] 0; echo "  | |____/ |    "
tput cup $[14+($height-25)] 0; echo "   \______/     "

sleep 1

Bubble " BASH IS BETTER THAN PERL "; sleep 2

tput cup $[11+($height-25)] 0; echo "    _____      "
tput cup $[12+($height-25)] 0; echo "   / ^ ^ \     "
tput cup $[13+($height-25)] 0; echo "  | \___/ |    "
tput cup $[14+($height-25)] 0; echo "   \_____/     "

Bubble "Only a joke *g* "; sleep 2
Bubble " Thats all folks! "; sleep 2

sleep 3
clear

echo -e "$OFF"
echo -en "made by texray (texray@fuckMicrosoft.com, http://texray.no-ip.org)\n\n"


