From 3f047022df05b597a0e100264441bc4cf834cd37 Mon Sep 17 00:00:00 2001 From: lepz0r Date: Tue, 28 Oct 2025 22:35:41 +0700 Subject: [PATCH 1/2] Add transparent background support --- gallery/alpha/alpha.sh | 5 ++++- gallery/bouncing/bouncing.sh | 5 ++++- gallery/cutesaver/cutesaver.sh | 4 +++- gallery/fireworks/fireworks.sh | 4 +++- gallery/matrix/matrix.sh | 4 +++- gallery/pipes/pipes.sh | 4 +++- gallery/rain/rain.sh | 4 +++- gallery/speaky/speaky.sh | 4 +++- screensaver.sh | 23 +++++++++++++++++------ 9 files changed, 43 insertions(+), 14 deletions(-) diff --git a/gallery/alpha/alpha.sh b/gallery/alpha/alpha.sh index b2592cb..07ec543 100755 --- a/gallery/alpha/alpha.sh +++ b/gallery/alpha/alpha.sh @@ -18,7 +18,10 @@ trap _cleanup_and_exit SIGINT # Ctrl‑C width=$(tput cols) height=$(tput lines) -tput setab 0 # black background + +if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background +fi clear tput civis # no cursor diff --git a/gallery/bouncing/bouncing.sh b/gallery/bouncing/bouncing.sh index 3d9d70b..ee18328 100755 --- a/gallery/bouncing/bouncing.sh +++ b/gallery/bouncing/bouncing.sh @@ -22,7 +22,10 @@ trap _cleanup_and_exit SIGINT # Ctrl‑C # Main animation loop # animate() { - tput setab 0 # black background + + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor diff --git a/gallery/cutesaver/cutesaver.sh b/gallery/cutesaver/cutesaver.sh index f8d7fec..1f30424 100755 --- a/gallery/cutesaver/cutesaver.sh +++ b/gallery/cutesaver/cutesaver.sh @@ -53,7 +53,9 @@ sleep 2 # Now we'll simply start the animation. animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor diff --git a/gallery/fireworks/fireworks.sh b/gallery/fireworks/fireworks.sh index 2c86138..4d0fca5 100755 --- a/gallery/fireworks/fireworks.sh +++ b/gallery/fireworks/fireworks.sh @@ -61,7 +61,9 @@ draw_firework() { # Main animation loop # animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor diff --git a/gallery/matrix/matrix.sh b/gallery/matrix/matrix.sh index 000b015..0364fc5 100755 --- a/gallery/matrix/matrix.sh +++ b/gallery/matrix/matrix.sh @@ -43,7 +43,9 @@ trap _cleanup_and_exit SIGINT # Catch Ctrl‑C # Main animation loop (Optimized) # animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor diff --git a/gallery/pipes/pipes.sh b/gallery/pipes/pipes.sh index f72a778..b0738a3 100755 --- a/gallery/pipes/pipes.sh +++ b/gallery/pipes/pipes.sh @@ -261,7 +261,9 @@ init_screen() { stty -echo tput smcup tput civis - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi tput clear resize diff --git a/gallery/rain/rain.sh b/gallery/rain/rain.sh index 35d8144..27a27c3 100755 --- a/gallery/rain/rain.sh +++ b/gallery/rain/rain.sh @@ -26,7 +26,9 @@ trap _cleanup_and_exit SIGINT # Ctrl‑C # Main animation loop (Optimized) # animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor diff --git a/gallery/speaky/speaky.sh b/gallery/speaky/speaky.sh index af9f43c..32c1e28 100755 --- a/gallery/speaky/speaky.sh +++ b/gallery/speaky/speaky.sh @@ -388,7 +388,9 @@ trap cleanup_and_exit SIGINT the_show_must_go_on() { lov_detect_engine lov_hide_cursor - lov_back_color 0 # Set background to black + if [[ ! transparent_background -eq 1 ]]; then + lov_back_color 0 # Set background to black + fi lov_clear_screen if [ -z "$LOV_TTS_ENGINE" ]; then diff --git a/screensaver.sh b/screensaver.sh index 16f4e2c..f62a289 100755 --- a/screensaver.sh +++ b/screensaver.sh @@ -17,6 +17,14 @@ BASH_SCREENSAVERS_COPYRIGHT='Copyright (c) 2025 Attogram Project /dev/null && pwd)/gallery" chosen_screensaver='' # the chosen one +transparent_background=0 + +# Set background +set_background(){ + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi +} # Peak into the gallery # @@ -219,7 +227,7 @@ main_menu() { run_random fi while true; do - tput setab 0 # black background + set_background tput setaf 2 # green foreground echo @@ -236,7 +244,7 @@ main_menu() { enjoy_a_screensaver "$chosen_screensaver" # run until user presses ^C screensaver_return=$? if (( screensaver_return )); then - tput setab 0 # black background + set_background tput setaf 1 # red foreground printf ' @@ -249,7 +257,7 @@ Oh no! Screensaver had trouble! Error code: %d } BASH_SCREENSAVERS_DESCRIPTION="A collection of screensavers written in bash." -BASH_SCREENSAVERS_USAGE="Usage: $0 [-h|--help] [-v|--version] [-n |--new ] [-r|--random] [name|number]" +BASH_SCREENSAVERS_USAGE="Usage: $0 [-h|--help] [-v|--version] [-n |--new ] [-r|--random] [-b|--transparent-background] [name|number]" run_direct() { local choice="$1" @@ -336,6 +344,9 @@ main() { main_menu "random" exit 0 ;; + -b|--transparent-background) + export transparent_background=1 + ;; *) run_direct "$1" exit 0 @@ -346,6 +357,6 @@ main() { } main "$@" - - - + + + From e16f00b7947916d152db92e29c9e47c91f206b21 Mon Sep 17 00:00:00 2001 From: lepz0r Date: Wed, 29 Oct 2025 01:32:31 +0700 Subject: [PATCH 2/2] Add transparent background support (2) --- gallery/stars/stars.sh | 10 ++++---- gallery/tunnel/tunnel.sh | 40 +++++++++++++++---------------- gallery/vibe/vibe.sh | 52 ++++++++++++++++++++-------------------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/gallery/stars/stars.sh b/gallery/stars/stars.sh index 4b8d51e..8bcdc75 100755 --- a/gallery/stars/stars.sh +++ b/gallery/stars/stars.sh @@ -17,9 +17,9 @@ DELAY=0.02 STARS=("*" "." "+" "'" "O") _cleanup_and_exit() { # handler for SIGINT (Ctrl‑C) - tput cnorm # show cursor - tput sgr0 # restore screen - exit 0 + tput cnorm # show cursor + tput sgr0 # restore screen + exit 0 } trap _cleanup_and_exit SIGINT # Ctrl‑C @@ -28,7 +28,9 @@ trap _cleanup_and_exit SIGINT # Ctrl‑C # Main animation loop # animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor diff --git a/gallery/tunnel/tunnel.sh b/gallery/tunnel/tunnel.sh index 87bd7d0..9a29375 100755 --- a/gallery/tunnel/tunnel.sh +++ b/gallery/tunnel/tunnel.sh @@ -10,10 +10,10 @@ COLORS=($'\e[31m' $'\e[32m' $'\e[33m' $'\e[34m' $'\e[35m' $'\e[36m') DELAY=0.02 _cleanup_and_exit() { # handler for SIGINT (Ctrl‑C) - tput cnorm # show the cursor again - tput sgr0 - echo - exit 0 + tput cnorm # show the cursor again + tput sgr0 + echo + exit 0 } trap _cleanup_and_exit SIGINT # Ctrl‑C @@ -22,7 +22,9 @@ trap _cleanup_and_exit SIGINT # Ctrl‑C # Main animation loop # animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor @@ -47,16 +49,15 @@ animate() { local is_moving=0 # Start in a paused state local next_state_change_time next_state_change_time=$(date +%s) - local move_duration=10 # seconds - local min_pause_duration=5 # seconds + local move_duration=10 # seconds + local min_pause_duration=5 # seconds local max_pause_duration=20 # seconds local angle_increment=0.005 # Slow down the movement - # Plot a point, checking for screen boundaries plot_point() { local x=$1 y=$2 char=$3 color=$4 - if (( x >= 0 && x < width && y >= 0 && y < height )); then + if ((x >= 0 && x < width && y >= 0 && y < height)); then frame_buffer+="\e[$((y + 1));$((x + 1))H${color}${char}" fi } @@ -64,7 +65,7 @@ animate() { # Erase a point, checking for screen boundaries erase_point() { local x=$1 y=$2 - if (( x >= 0 && x < width && y >= 0 && y < height )); then + if ((x >= 0 && x < width && y >= 0 && y < height)); then frame_buffer+="\e[$((y + 1));$((x + 1))H " fi } @@ -73,8 +74,8 @@ animate() { # --- State management for movement --- local current_time current_time=$(date +%s) - if (( current_time >= next_state_change_time )); then - if (( is_moving )); then + if ((current_time >= next_state_change_time)); then + if ((is_moving)); then # Transition to paused state is_moving=0 local pause_duration=$((RANDOM % (max_pause_duration - min_pause_duration + 1) + min_pause_duration)) @@ -87,7 +88,7 @@ animate() { fi # --- Update center coordinates only when moving --- - if (( is_moving )); then + if ((is_moving)); then # When moving, the center of the tunnel is continuously recalculated # to create the illusion of flying through a turning tunnel. read -r angle center_x center_y < <(awk -v angle="$angle" \ @@ -102,22 +103,21 @@ animate() { }') fi - frame_buffer="" # Add a new ribbon every few frames - if (( frame_counter % ribbon_spacing == 0 )); then + if ((frame_counter % ribbon_spacing == 0)); then radii+=("1 $center_x $center_y") fi local -a next_radii=() for ridge_data in "${radii[@]}"; do local r cx cy - read -r r cx cy <<< "$ridge_data" + read -r r cx cy <<<"$ridge_data" if [ $r -gt 0 ]; then - local prev_r=$((r-1)) + local prev_r=$((r - 1)) # Erase the previous shape - for ((i=0; i < prev_r; i++)); do + for ((i = 0; i < prev_r; i++)); do erase_point $((cx + i)) $((cy - prev_r + i)) erase_point $((cx + prev_r - i)) $((cy + i)) erase_point $((cx - i)) $((cy + prev_r - i)) @@ -128,7 +128,7 @@ animate() { local color=${COLORS[$((r % ${#COLORS[@]}))]} local char=${CHARS[$((r % ${#CHARS[@]}))]} # Draw a square/diamond shape - for ((i=0; i < r; i++)); do + for ((i = 0; i < r; i++)); do plot_point $((cx + i)) $((cy - r + i)) "$char" "$color" plot_point $((cx + r - i)) $((cy + i)) "$char" "$color" plot_point $((cx - i)) $((cy + r - i)) "$char" "$color" @@ -137,7 +137,7 @@ animate() { # Increment radius for the next frame, and keep it if it's not too large local next_r=$((r + 1)) - if (( next_r < max_radius )); then + if ((next_r < max_radius)); then next_radii+=("$next_r $cx $cy") fi done diff --git a/gallery/vibe/vibe.sh b/gallery/vibe/vibe.sh index 03f94dd..86b72fb 100755 --- a/gallery/vibe/vibe.sh +++ b/gallery/vibe/vibe.sh @@ -9,22 +9,22 @@ # --- Configuration --- # Color palette for the "dark -> bright -> dark" cycle. PALETTE=( - $'\e[38;5;22m' # Dark Green + $'\e[38;5;22m' # Dark Green $'\e[38;5;28m' $'\e[38;5;34m' $'\e[38;5;40m' - $'\e[38;5;46m' # Bright Green + $'\e[38;5;46m' # Bright Green $'\e[38;5;82m' $'\e[38;5;118m' - $'\e[38;5;45m' # Bright Blue + $'\e[38;5;45m' # Bright Blue $'\e[38;5;39m' $'\e[38;5;33m' $'\e[38;5;27m' - $'\e[38;5;21m' # Dark Blue - $'\e[38;5;52m' # Dark Purple + $'\e[38;5;21m' # Dark Blue + $'\e[38;5;52m' # Dark Purple $'\e[38;5;93m' $'\e[38;5;129m' - $'\e[38;5;165m' # Bright Purple + $'\e[38;5;165m' # Bright Purple ) RESET=$'\e[0m' @@ -49,35 +49,34 @@ CONTENT=( ) GLITCHES=( -" + " _ _ ( \/ ) \ / )( (__) " -" + " ____ (____) (____) (____) " -"SYNTAX ERROR" -"DECOMPILING..." + "SYNTAX ERROR" + "DECOMPILING..." ) - # The maximum length of the character streams MAX_STREAM_LEN=20 # Animation speed (lower is faster) DELAY=0.04 _cleanup_and_exit() { # handler for SIGINT (Ctrl‑C) - tput cnorm # show the cursor again - tput sgr0 # reset all attributes - clear - echo - exit 0 + tput cnorm # show the cursor again + tput sgr0 # reset all attributes + clear + echo + exit 0 } trap _cleanup_and_exit SIGINT # Catch Ctrl‑C @@ -86,7 +85,9 @@ trap _cleanup_and_exit SIGINT # Catch Ctrl‑C # Main animation loop (Optimized) # animate() { - tput setab 0 # black background + if [[ ! transparent_background -eq 1 ]]; then + tput setab 0 # black background + fi clear tput civis # Hide cursor @@ -97,12 +98,12 @@ animate() { 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 + 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 local -a stream_content - for ((i=0; i