Skip to content

Instantly share code, notes, and snippets.

@ponceto
Last active August 18, 2023 16:53
Show Gist options
  • Save ponceto/b7bc2c5beb56b2441dfbc29da34e0560 to your computer and use it in GitHub Desktop.
Save ponceto/b7bc2c5beb56b2441dfbc29da34e0560 to your computer and use it in GitHub Desktop.
Matrix characterfall on your terminal

Matrix characterfall effect

Abstract

These scripts are written to simulate the matrix characterfall on your terminal.

ASCII version

This is a version with a pure ascii charset of the matrix effect.

matrix-ascii.sh

Hiragana version

This is a version with a unicode hiragana charset of the matrix effect.

matrix-hiragana.sh
#!/bin/bash
#
# revamped and adapted from CommandLineMagic on Twitter @climagic
#
# https://twitter.com/climagic/status/1472931718214651912
#
# Ascii charset
#
# ----------------------------------------------------------------------------
# globals
# ----------------------------------------------------------------------------
ROWS=$(tput lines)
COLS=$(tput cols)
# ----------------------------------------------------------------------------
# the character waterfall
# ----------------------------------------------------------------------------
while :
do
RAND=${RANDOM}
CHAR=$((32 + (${RAND} % 96)))
HEXA=$(printf "%02X" "${CHAR}")
CODE=$(printf "\x${HEXA}")
echo "${ROWS} ${COLS} $((${RAND} % ${COLS})) ${CODE}"
sleep 0.05
done | gawk '{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,$4;printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,$4;if (a[x] >= $1){a[x]=0;} }}'
# ----------------------------------------------------------------------------
# End-Of-File
# ----------------------------------------------------------------------------
#!/bin/bash
#
# revamped and adapted from CommandLineMagic on Twitter @climagic
#
# https://twitter.com/climagic/status/1472931718214651912
#
# Hiragana charset, thanks to Benjamin Bellamy
#
# ----------------------------------------------------------------------------
# globals
# ----------------------------------------------------------------------------
ROWS=$(tput lines)
COLS=$(tput cols)
# ----------------------------------------------------------------------------
# the character waterfall
# ----------------------------------------------------------------------------
while :
do
RAND=${RANDOM}
CHAR=$((12449 + (${RAND} % 89)))
HEXA=$(printf "%02X" "${CHAR}")
CODE=$(printf "\u${HEXA}")
echo "${ROWS} ${COLS} $((${RAND} % ${COLS})) ${CODE}"
sleep 0.05
done | gawk '{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,$4;printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,$4;if (a[x] >= $1){a[x]=0;} }}'
# ----------------------------------------------------------------------------
# End-Of-File
# ----------------------------------------------------------------------------
@ponceto
Copy link
Author

ponceto commented Dec 23, 2021

@benjaminbellamy updated ! Thanks for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment