Matrix Effect

Copy and paste the commands below into your bash shell. Or better yet read, type and learn. Upon running this will create the Matrix effect in your terminal. Make sure you have gawk installed. Standard awk will not work due to buffering problems. Also, you might want to try a different terminal if you're not seeing the bold lead character and non-bold trail. $RANDOM is not really a good random source. If you look closely its using the same character in each column. This is because in quick succession, $RANDOM will generate the same number for a second before moving on to the next.

echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|gawk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'

Instead of manually creating your list of characters, you could also use the jot command to auto generate the available ascii characters for you.

echo -e "\e[1;40m" ; clear ; characters=$( jot -c 94 33 | tr -d '\n' ) ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) $characters ;sleep 0.05; done|gawk '{ letters=$5; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'

And below is another version that uses characters from Unicode.

echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $( printf "\U$(( $RANDOM % 500 ))" ) ;sleep 0.05; done|gawk '{c=$4; letter=$4;a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'

Run "reset" after canceling this if you want to fix your terminal colors.

There is also a program called cmatrix written 10 years ago that does a more accurate representation of the Matrix effect, but of course the whole point of the exercise above was to show that it could be done fairly easily with already installed tools in just a few lines. However cmatrix is notable because it was written by Chris Allegretta, the same guy who wrote the popular nano editor. Chris also has a good sense of hacker style.

New for 2015, click here to order your official climagic t-shirt

climagic home page

Created: 2011-12-20

Updated: 2015-10-31

blog comments powered by Disqus