Last active
September 26, 2017 17:22
-
-
Save funasoul/5d3c89f1876b78ac2cfea6b2ec176a79 to your computer and use it in GitHub Desktop.
Create animated gif files from simulation results generated by SpatialSimulator
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
spatial2gif() { | |
# Create animated gif files from simulation results generated by [SpatialSimulator](https://github.com/funasoul/docker-spatialsim) | |
local width="400" | |
local opt_resize="${width}" | |
# -h, --help options | |
if [[ "$1" = "-h" || "$1" = "-help" || "$1" = "--help" || "$1" = "--h" ]]; then | |
echo "Usage: $0 [width] [height]" | |
echo " Create animated GIF files from simulation results generated by" | |
echo " SpatialSimulator." | |
echo " - [width] ... width of animated GIF file (default: $width)" | |
echo " - [height] ... height of animated GIF file (default: none)" | |
echo " If only width is specified, height is automatically" | |
echo " calculated from original image files." | |
return | |
fi | |
# accept width as first argv, height as second argv (both optional) | |
if [ $# -gt 1 ]; then | |
width=$1 | |
height=$2 | |
opt_resize="${width}x${height}" | |
elif [ $# = 1 ]; then | |
width=$1 | |
opt_resize="${width}" | |
fi | |
local model=$(basename $PWD) | |
if [ ! -d img ]; then | |
echo "No img/ dir in this directory. Please chdir to a directory which contains img/ directory." | |
echo "(ex.) cd ~/git/docker-spatialsim/result/sam2d/" | |
else | |
echo "Converting simulation results of $model to animated gif ..." | |
foreach i (img/*~img/geometry*) | |
local species=$(basename $i) | |
echo -ne " Processing species $species ##### ( 33%)\r" | |
convert -delay 10 -loop 0 $i/????.png ${species}.gif | |
echo -ne " Processing species $species ########## ( 66%)\r" | |
convert ${species}.gif -coalesce tmp_${species}.gif | |
echo -ne " Processing species $species ############### (100%)" | |
convert tmp_${species}.gif -resize $opt_resize ${model}_${species}.gif | |
rm -f ${species}.gif tmp_${species}.gif | |
echo " --> ${model}_${species}.gif" | |
end | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment