Commit 0652d1682e7a67f221d93ac168a8fedfaa2eb530
1 parent
83e4d81b44
Exists in
master
matrix script
Showing 1 changed file with 74 additions and 0 deletions Side-by-side Diff
scripts/matrixish.sh
View file @
0652d16
1 | +#!/bin/bash | |
2 | +# | |
3 | +# matrix: matrix-ish display for Bash terminal | |
4 | +# Author: Brett Terpstra 2012 <http://brettterpstra.com> | |
5 | +# Contributors: Lauri Ranta and Carl <http://blog.carlsensei.com/> | |
6 | +# | |
7 | +# A morning project. Could have been better, but I'm learning when to stop. | |
8 | + | |
9 | +### Customization: | |
10 | +blue="\033[0;34m" | |
11 | +brightblue="\033[1;34m" | |
12 | +cyan="\033[0;36m" | |
13 | +brightcyan="\033[1;36m" | |
14 | +green="\033[0;32m" | |
15 | +brightgreen="\033[1;32m" | |
16 | +red="\033[0;31m" | |
17 | +brightred="\033[1;31m" | |
18 | +white="\033[1;37m" | |
19 | +black="\033[0;30m" | |
20 | +grey="\033[0;37m" | |
21 | +darkgrey="\033[1;30m" | |
22 | +# Choose the colors that will be used from the above list | |
23 | +# space-separated list | |
24 | +# e.g. `colors=($green $brightgreen $darkgrey $white)` | |
25 | +colors=($green $brightgreen) | |
26 | +### End customization | |
27 | + | |
28 | +### Do not edit below this line | |
29 | +spacing=${1:-100} # the likelihood of a character being left in place | |
30 | +scroll=${2:-0} # 0 for static, positive integer determines scroll speed | |
31 | +screenlines=$(expr `tput lines` - 1 + $scroll) | |
32 | +screencols=$(expr `tput cols` / 2 - 1) | |
33 | + | |
34 | +# 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 ^) | |
35 | +# charset via Carl: | |
36 | +chars=(ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン) | |
37 | + | |
38 | +count=${#chars[@]} | |
39 | +colorcount=${#colors[@]} | |
40 | + | |
41 | +trap "tput sgr0; clear; exit" SIGTERM SIGINT | |
42 | + | |
43 | +if [[ $1 =~ '-h' ]]; then | |
44 | + echo "Display a Matrix(ish) screen in the terminal" | |
45 | + echo "Usage: matrix [SPACING [SCROLL]]" | |
46 | + echo "Example: matrix 100 0" | |
47 | + exit 0 | |
48 | +fi | |
49 | + | |
50 | + | |
51 | +clear | |
52 | +tput cup 0 0 | |
53 | +while : | |
54 | + do for i in $(eval echo {1..$screenlines}) | |
55 | + do for i in $(eval echo {1..$screencols}) | |
56 | + do rand=$(($RANDOM%$spacing)) | |
57 | + case $rand in | |
58 | + 0) | |
59 | + printf "${colors[$RANDOM%$colorcount]}${chars[$RANDOM%$count]} " | |
60 | + ;; | |
61 | + 1) | |
62 | + printf " " | |
63 | + ;; | |
64 | + *) | |
65 | + printf "\033[2C" | |
66 | + ;; | |
67 | + esac | |
68 | + done | |
69 | + printf "\n" | |
70 | + | |
71 | + # sleep .005 | |
72 | + done | |
73 | + tput cup 0 0 | |
74 | + done |