74 lines
1.7 KiB
Bash
Executable File
74 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Repeatedly invoke script for animation
|
|
#
|
|
# Copyright (C) 2018 Mike Gerwitz
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
##
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
usage()
|
|
{
|
|
cat <<EOF
|
|
Usage: $0 script frame [speed]
|
|
Recursively render FRAME using SCRIPT
|
|
|
|
The current frame is stored in the file \`last-frame' in the working
|
|
directory. It may be used to continue the animation after quitting,
|
|
or save the state of the system.
|
|
|
|
SPEED should be a value recognized by the \`sleep' command. It defaults
|
|
to 0.25 to give some level of appreciation for each frame while still
|
|
looking animated. It looks fairly smooth at 0.05 but can go much faster on
|
|
modern systems.
|
|
|
|
Example:
|
|
$0 fall.sed fall/frame-lalaloop
|
|
EOF
|
|
|
|
exit 64 # EX_USAGE
|
|
}
|
|
|
|
|
|
render()
|
|
{
|
|
local -r speed=${1?Missing speed}
|
|
|
|
# use tput rather than clear to avoid flicker
|
|
tput cup 0 0
|
|
cat last-frame
|
|
sleep "$speed"
|
|
}
|
|
|
|
|
|
main()
|
|
{
|
|
test $# -ge 2 -a $# -le 3 || usage
|
|
|
|
local -r script=${1?Missing script}
|
|
local -r frame=${2?Missing initial frame}
|
|
local -r speed=${3:-0.25}
|
|
|
|
cp "$frame" last-frame
|
|
|
|
clear
|
|
render "$speed"
|
|
|
|
while sed -f "$script" -i last-frame; do render "$speed"; done
|
|
}
|
|
|
|
main "$@"
|