Skip to content

Instantly share code, notes, and snippets.

@frank-bg
Forked from ponceto/README.md
Created April 16, 2023 20:04
Show Gist options
  • Save frank-bg/a33bae2a0619577b32a5a6932ce740dd to your computer and use it in GitHub Desktop.
Save frank-bg/a33bae2a0619577b32a5a6932ce740dd 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
# ----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment