Skip to content

Instantly share code, notes, and snippets.

@dhaiducek
Last active June 2, 2026 18:38
Show Gist options
  • Select an option

  • Save dhaiducek/174cdb04a5a51f016c6ca69ece721b17 to your computer and use it in GitHub Desktop.

Select an option

Save dhaiducek/174cdb04a5a51f016c6ca69ece721b17 to your computer and use it in GitHub Desktop.
Modified Matrix Effect (original from @khakimov)
#!/bin/bash
# shellcheck disable=SC2016
awkscript='
{
lines=$1;
random_col=$3;
letter=$4;
cols[random_col]=0;
for (col in cols) {
rnum = int(20*rand());
if (int(col) > int($2))
col = $2;
if (int(cols[col]) < 0) {
line=-cols[col];
cols[col]=cols[col]-1;
printf "\033[%s;%sH%s", line, col, " ";
if (int(-cols[col]) >= int(lines)) {
cols[col]=0;
} else if (int(rnum) < 1) {
cols[col]=0;
}
} else {
line=cols[col];
cols[col]=cols[col]+1;
if (int(rnum) < 3) {
printf "\033[%s;%sH\033[1;32m%s\033[0m", line, col, letter;
} else {
printf "\033[%s;%sH\033[2;32m%s\033[0m", line, col, letter;
}
printf "\033[%s;%sH\033[37m%s\033[0;0H\033[0m", cols[col], col, letter;
if (int(cols[col]) >= int(lines)) {
if (int(rnum) < 2) {
cols[col]=0;
} else {
cols[col]=-1;
}
}
}
}
}
'
echo -e "\e[1;40m"
clear
if [[ -t 0 ]]; then
stty -echo -icanon -icrnl time 0 min 0;
fi
keypress=''
while [ -z "${keypress}" ]; do
lines=$(tput lines)
cols=$(tput cols)
echo "${lines}" "${cols}" $(( RANDOM % cols)) $(( RANDOM % 2 ))
sleep 0.04
keypress=$(cat -v)
done | awk "${awkscript}"
if [[ -t 0 ]]; then
stty sane;
fi
# clear
exit 0
@gadget00
Copy link
Copy Markdown

gadget00 commented Nov 5, 2019

I only get a black screen with a single "0" or "1" on the screen. It doesnt keep on writing on the screen.

Im using the Linux subsystem in Win10. Would that be causing this?

@dhaiducek
Copy link
Copy Markdown
Author

@gadget00 Unfortunately I'm not familiar with the Linux subsystem, but there could be some commands or escape sequences that don't work the same. I wonder: What's the output of tput lines or tput cols?

@gadget00
Copy link
Copy Markdown

tput lines: 30

tput cols: 120

@rullinoiz
Copy link
Copy Markdown

this is epic

@Boddah
Copy link
Copy Markdown

Boddah commented Jun 29, 2020

Loved this. Hoping the serial connection to my new (lol) HP 700/96 is quick enough to run it.
Just a quick update to expand from using just 0's and 1's:

8,10c8,12
< lines=$1
< random_col=$3
< letter=$4
---
> lines=$1;
> random_col=$3;
> rand_char=$4;
> charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()";
> letter=substr(charset,rand_char,1);
55c57
< echo $lines $cols $(( $RANDOM % $cols)) $(( $RANDOM % 2 ))
---
> echo $lines $cols $(( $RANDOM % $cols)) $(( $RANDOM % 70 ))
65a68
>

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