Last active
May 1, 2025 11:19
-
-
Save flnnn/46bd8c3d5b39f383dd91e9e08fb977fd to your computer and use it in GitHub Desktop.
Terminal Matrix Effect - Bash Only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Developed for Bash. | |
""" | |
import time | |
import random | |
import shutil | |
import argparse | |
def clear_terminal(): | |
print("\033[H", end="") | |
def render_matrix(matrix): | |
for row in matrix: | |
print("".join(row)) | |
def loop(matrix, rows, columns, speed): | |
max_column_index = columns - 1 | |
chosen_column = random.randint(0, max_column_index) | |
filled_columns = set() | |
random_rows = rows - 1 | |
filled = 0 | |
depth = 0 | |
while filled < columns: | |
time.sleep(speed) | |
clear_terminal() | |
render_matrix(matrix) | |
if depth < random_rows: | |
symbol = random.choice("01$#@&%!?+={`*)(") | |
brightness = ["\033[1;32m", "\033[7;32m", "\033[2;32m"] + ["\033[32m"] * 3 | |
matrix[depth][chosen_column] = random.choice(brightness) + symbol + "\033[m" | |
depth += 1 | |
if depth == random_rows: | |
filled_columns.add(chosen_column) | |
filled += 1 | |
chosen_column = random.randint(0, max_column_index) | |
while chosen_column in filled_columns: | |
chosen_column = random.randint(0, max_column_index) | |
depth = 0 | |
random_rows = random.randint(5, rows - 1) | |
def main(): | |
parser = argparse.ArgumentParser( | |
description=";;; [ Terminal Matrix Effect ] ;;;" | |
) | |
parser.add_argument("--terminal", action="store_true", help="Use terminal's dimensions for the effect area.") | |
parser.add_argument("--custom", help="Configure number of rows and columns. Notation: N_ROWSxN_COLUMNS.") | |
args = parser.parse_args() | |
sizes = shutil.get_terminal_size() | |
if args.terminal: | |
rows = sizes.lines - 5 | |
columns = sizes.columns | |
elif args.custom: | |
rows, columns = map(int, args.custom.split("x")) | |
print(rows, columns) | |
speed = 0.03 | |
matrix = [[' ' for _ in range(0, columns)] for _ in range(0, rows)] | |
try: | |
loop(matrix, rows, columns, speed) | |
except KeyboardInterrupt: | |
print("\n\033[1;32mBye\033[m") | |
except Exception: | |
pass | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment