#!/usr/bin/env bash #~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- # MATRIX - A simple, FAST matrix-style screensaver # # This version is optimized for speed by: # 1. Using direct ANSI escape codes instead of forking `tput` for every update. # 2. Building a "frame buffer" string with all screen changes for a frame. # 3. Printing the entire frame buffer with a single `printf` call. #~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- # --- Configuration --- # Color palette for the "dark -> bright -> dark" cycle. PALETTE=( $'\e[38;5;22m' # Darkest $'\e[38;5;28m' $'\e[38;5;34m' $'\e[38;5;40m' $'\e[38;5;46m' # Brightest $'\e[38;5;40m' $'\e[38;5;34m' $'\e[38;5;28m' ) RESET=$'\e[0m' # The characters to display CHARS="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()" # The maximum length of the character streams MAX_STREAM_LEN=15 # Animation speed (lower is faster) DELAY=0.04 _cleanup_and_exit() { # handler for SIGINT (Ctrl‑C) tput cnorm # show cursor tput sgr0 # restore screen exit 0 } trap _cleanup_and_exit SIGINT # Catch Ctrl‑C # # Main animation loop (Optimized) # animate() { tput setab 0 # black background clear tput civis # Hide cursor # Get terminal dimensions local width width=$(tput cols) local height height=$(tput lines) # Initialize column arrays local -a heads # y-position of the head of the stream local -a stream_lengths # length of the stream local -a active_cols # 1 if column is active, 0 if not for ((i=0; i