havin a bash

Post about your projects!
Posts: 3
Joined: Sun Feb 02, 2014 6:57 pm
Location: United States

havin a bash

Unread postby leohJones » Mon Feb 03, 2014 7:51 pm

Courtesy of TKM who came to 2 meetings in June:


heres a script for terminal snow
Code: Select all
        #!/bin/bash
         
        LINES=$(tput lines)
        COLUMNS=$(tput cols)
         
        declare -A snowflakes
        declare -A lastflakes
         
        clear
         
        function move_flake() {
        i="$1"
         
        if [ "${snowflakes[$i]}" = "" ] || [ "${snowflakes[$i]}" = "$LINES" ]; then
        snowflakes[$i]=0
        else
        if [ "${lastflakes[$i]}" != "" ]; then
        printf "\033[%s;%sH \033[1;1H " ${lastflakes[$i]} $i
        fi
        fi
         
        printf "\033[%s;%sH*\033[1;1H" ${snowflakes[$i]} $i
         
        lastflakes[$i]=${snowflakes[$i]}
        snowflakes[$i]=$((${snowflakes[$i]}+1))
        }
         
        while :
        do
        i=$(($RANDOM % $COLUMNS))
         
        move_flake $i
         
        for x in "${!lastflakes[@]}"
        do
        move_flake "$x"
        done
         
        sleep 0.1
        done




and heres 2 for the matrix
Code: Select all
#!/bin/bash
#
# matrix: matrix-ish display for Bash terminal
# Author: Brett Terpstra 2012 <http://brettterpstra.com>
# Contributors: Lauri Ranta and Carl <http://blog.carlsensei.com/>
#
# A morning project. Could have been better, but I'm learning when to stop.
 
### Customization:
blue="\033[0;34m"
brightblue="\033[1;34m"
cyan="\033[0;36m"
brightcyan="\033[1;36m"
green="\033[0;32m"
brightgreen="\033[1;32m"
red="\033[0;31m"
brightred="\033[1;31m"
white="\033[1;37m"
black="\033[0;30m"
grey="\033[0;37m"
darkgrey="\033[1;30m"
# Choose the colors that will be used from the above list
# space-separated list
# e.g. `colors=($green $brightgreen $darkgrey $white)`
colors=($green $brightgreen)
### End customization
 
### Do not edit below this line
spacing=${1:-100} # the likelihood of a character being left in place
scroll=${2:-0} # 0 for static, positive integer determines scroll speed
screenlines=$(expr `tput lines` - 1 + $scroll)
screencols=$(expr `tput cols` / 2 - 1)
 
# chars=(a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ^)
# charset via Carl:
chars=(ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン)
 
count=${#chars[@]}
colorcount=${#colors[@]}
 
trap "tput sgr0; clear; exit" SIGTERM SIGINT
 
if [[ $1 =~ '-h' ]]; then
echo "Display a Matrix(ish) screen in the terminal"
echo "Usage: matrix [SPACING [SCROLL]]"
echo "Example: matrix 100 0"
exit 0
fi
 
 
clear
tput cup 0 0
while :
do for i in $(eval echo {1..$screenlines})
do for i in $(eval echo {1..$screencols})
do rand=$(($RANDOM%$spacing))
case $rand in
0)
printf "${colors[$RANDOM%$colorcount]}${chars[$RANDOM%$count]} "
;;
1)
printf " "
;;
*)
printf "\033[2C"
;;
esac
done
printf "\n"
 
# sleep .005
done
tput cup 0 0
done



another
Code: Select all
#!/bin/bash
#
# matrix: matrix-ish display for Bash terminal
# Author: Brett Terpstra 2012 <http://brettterpstra.com>
# Contributors: Lauri Ranta and Carl <http://blog.carlsensei.com/>
#
# A morning project. Could have been better, but I'm learning when to stop.
 
### Customization:
blue="\033[0;34m"
brightblue="\033[1;34m"
cyan="\033[0;36m"
brightcyan="\033[1;36m"
green="\033[0;32m"
brightgreen="\033[1;32m"
red="\033[0;31m"
brightred="\033[1;31m"
white="\033[1;37m"
black="\033[0;30m"
grey="\033[0;37m"
darkgrey="\033[1;30m"
# Choose the colors that will be used from the above list
# space-separated list
# e.g. `colors=($green $brightgreen $darkgrey $white)`
colors=($green $brightgreen)
### End customization
 
### Do not edit below this line
spacing=${1:-100} # the likelihood of a character being left in place
scroll=${2:-0} # 0 for static, positive integer determines scroll speed
screenlines=$(expr `tput lines` - 1 + $scroll)
screencols=$(expr `tput cols` / 2 - 1)
 
# chars=(a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ^)
# charset via Carl:
# chars=(ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン)
chars=(А Б В Г Д Е Ё Ж З І Й К Л М Н О П Р С Т У Ў Ф Х Ц Ч Ш Ы Ь Э Ю Я 0 1 2 3 4 5 6 7 8 9)
 
count=${#chars[@]}
colorcount=${#colors[@]}
 
trap "tput sgr0; clear; exit" SIGTERM SIGINT
 
if [[ $1 =~ '-h' ]]; then
echo "Display a Matrix(ish) screen in the terminal"
echo "Usage: matrix [SPACING [SCROLL]]"
echo "Example: matrix 100 0"
exit 0
fi
 
 
clear
tput cup 0 0
while :
do for i in $(eval echo {1..$screenlines})
do for i in $(eval echo {1..$screencols})
do rand=$(($RANDOM%$spacing))
case $rand in
0)
printf "${colors[$RANDOM%$colorcount]}${chars[$RANDOM%$count]} "
;;
1)
printf " "
;;
*)
printf "\033[2C"
;;
esac
done
printf "\n"
 
# sleep .005
done
tput cup 0 0
done



Posts: 1
Joined: Thu Feb 20, 2014 5:42 pm

Re: havin a bash

Unread postby EricLovejoy » Thu Feb 20, 2014 5:52 pm

Heres a script to make my gf happy.
http://nanocluster.umeche.maine.edu/bot/cbot

Return to Projects

Who is online

Users browsing this forum: No registered users and 3 guests