bugfix, esthetic cleanup, better comments, version bump

This commit is contained in:
Geoffray Levasseur-Brandin
2024-06-21 16:19:44 +02:00
parent 9e49e3e4d7
commit bef205ae84
18 changed files with 634 additions and 571 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details.
@@ -43,7 +44,7 @@ rain()
local rain_colors=("\e[37m" "\e[37;1m")
# More from 256 color mode
for i in {244..255}; do
rain_colors=( "${rain_colors[@]}" "\e[38;5;${i}m" )
rain_colors=("${rain_colors[@]}" "\e[38;5;${i}m")
done
local rain_tab=${#rain_cars[@]}
local rain_color_tab=${#rain_colors[@]}
@@ -54,18 +55,17 @@ rain()
local X=0 Y=0 drop_length=0 rain_drop=0
local max_rain_width=0 new_rain_odd=0 falling_odd=0
sigwinch() {
term_width=$(tput cols)
term_height=$(tput lines)
#step_duration=0.025
(( max_rain_width = term_width * term_height / 4 ))
(( max_rain_height = term_height < 10 ? 1 : term_height / 10 ))
((max_rain_width = term_width * term_height / 4))
((max_rain_height = term_height < 10 ? 1 : term_height / 10))
# In percentage
(( new_rain_odd = term_height > 50 ? 100 : term_height * 2 ))
(( new_rain_odd = new_rain_odd * 75 / 100 ))
(( falling_odd = term_height > 25 ? 100 : term_height * 4 ))
(( falling_odd = falling_odd * 90 / 100 ))
((new_rain_odd = term_height > 50 ? 100 : term_height * 2))
((new_rain_odd = new_rain_odd * 75 / 100))
((falling_odd = term_height > 25 ? 100 : term_height * 4))
((falling_odd = falling_odd * 90 / 100))
}
do_exit() {
@@ -80,19 +80,19 @@ rain()
Y=${rains[idx + 1]}
drop_length=${rains[idx + 4]}
for ((y = Y; y < Y + drop_length; y++)); do
(( y < 1 || y > term_height )) && continue
((y < 1 || y > term_height)) && continue
echo -ne "\e[${y};${X}H "
done
done
for ((idx = 0; idx < num_rains * num_rain_metadata; idx += num_rain_metadata)); do
if (( 100 * RANDOM / 32768 < falling_odd )); then
if ((100 * RANDOM / 32768 < falling_odd)); then
# Falling
if (( ++rains[idx + 1] > term_height )); then
if ((++rains[idx + 1] > term_height)); then
# Out of screen, bye sweet <3
rains=("${rains[@]:0:idx}"
"${rains[@]:idx+num_rain_metadata:num_rains*num_rain_metadata}")
(( num_rains-- ))
((num_rains--))
continue
fi
fi
@@ -102,7 +102,7 @@ rain()
drop_color=${rains[idx + 3]}
drop_length=${rains[idx + 4]}
for ((y = Y; y < Y + drop_length; y++)); do
(( y < 1 || y > term_height )) && continue
((y < 1 || y > term_height)) && continue
echo -ne "\e[${y};${X}H${drop_color}${rain_drop}"
done
done
@@ -118,24 +118,24 @@ rain()
local rains=()
local num_rains=0
sigwinch
while (( exit_st <= 0 )); do
if (( $exit_st <=0 )); then
while ((exit_st <= 0)); do
if (($exit_st <= 0)); then
read -n 1 -t $step_duration ch
case "$ch" in
q|Q)
do_exit
q | Q)
do_exit
;;
esac
if (( num_rains < max_rain_width )) && (( 100 * RANDOM / 32768 < new_rain_odd )); then
if ((num_rains < max_rain_width)) && ((100 * RANDOM / 32768 < new_rain_odd)); then
# Need new |, 1-based
rain_drop="${rain_cars[rain_tab * RANDOM / 32768]}"
drop_color="${rain_colors[rain_color_tab * RANDOM / 32768]}"
drop_length=$(( max_rain_height * RANDOM / 32768 + 1 ))
X=$(( term_width * RANDOM / 32768 + 1 ))
Y=$(( 1 - drop_length ))
rains=( "${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length" )
(( num_rains++ ))
drop_length=$((max_rain_height * RANDOM / 32768 + 1))
X=$((term_width * RANDOM / 32768 + 1))
Y=$((1 - drop_length))
rains=("${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length")
((num_rains++))
fi
# Let rain fall!
@@ -152,3 +152,6 @@ rain()
trap - WINCH
}
export -f rain
# ------------------------------------------------------------------------------
# EOF