2021-08-10 22:07:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-09-16 14:42:59 +00:00
|
|
|
###########################
|
|
|
|
#
|
|
|
|
# Run the stipple_gen script on a sequence
|
|
|
|
# of PNG images and then render the resulting
|
|
|
|
# preview images into a video.
|
|
|
|
#
|
|
|
|
###########################
|
|
|
|
|
2021-09-10 04:37:08 +00:00
|
|
|
if [[ "${1}" == "" ]]; then
|
|
|
|
echo "Please provide a directory of images as the first argument"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-10 22:07:26 +00:00
|
|
|
INPUT=`realpath "${1}"`
|
|
|
|
OUTPUT=`realpath "${2}"`
|
2021-09-09 00:53:52 +00:00
|
|
|
INVERT="${3}"
|
|
|
|
|
2021-09-10 04:37:08 +00:00
|
|
|
if [ ! -d "${INPUT}" ]; then
|
|
|
|
echo "Directory ${1} doesn't exist"
|
|
|
|
exit 2
|
2021-09-09 00:53:52 +00:00
|
|
|
fi
|
2021-08-10 22:07:26 +00:00
|
|
|
|
2021-09-10 04:37:08 +00:00
|
|
|
mkdir -p "${OUTPUT}"
|
|
|
|
|
2021-09-16 14:42:59 +00:00
|
|
|
FRAMERATE=12
|
2021-08-10 22:07:26 +00:00
|
|
|
WIDTH=404
|
|
|
|
HEIGHT=374
|
2021-11-29 02:59:21 +00:00
|
|
|
DOTSIZE=6
|
2021-11-27 03:01:07 +00:00
|
|
|
MAXGENERATIONS=50
|
2021-11-29 02:59:21 +00:00
|
|
|
MAXPARTICLES=900
|
|
|
|
MINDOTSIZE=0.5
|
|
|
|
LINE=0.5
|
2021-08-10 22:07:26 +00:00
|
|
|
FILL=true
|
2021-11-27 03:01:07 +00:00
|
|
|
MODE="stipple" #stipple/tsp
|
|
|
|
|
|
|
|
if [[ "${INVERT}" == "" ]]; then
|
|
|
|
INVERT="false"
|
|
|
|
fi
|
2021-08-12 04:52:37 +00:00
|
|
|
|
|
|
|
IMAGES=""
|
2021-08-10 22:07:26 +00:00
|
|
|
|
|
|
|
#files in dir
|
|
|
|
for png in "${INPUT}/"*.png ; do
|
|
|
|
filename=`basename "${png}"`
|
|
|
|
name=`echo "${filename}" | cut -d'.' -f1`
|
|
|
|
num=`echo "${name}" | awk -F'_' '{print $(NF)}'`
|
|
|
|
tmp=`mktemp`.png
|
|
|
|
bash white.sh "${png}" "${tmp}"
|
|
|
|
cd ~/src/stipple_gen/
|
2021-08-12 04:52:37 +00:00
|
|
|
if [ "${IMAGES}" == "" ]; then
|
|
|
|
part=`echo "${name}" | awk -F'_0' '{print $1}'`
|
|
|
|
IMAGES="${OUTPUT}/${part}_%06d_rendered.png"
|
|
|
|
VIDEO="${OUTPUT}/${part}.mov"
|
|
|
|
fi
|
2021-08-10 22:07:26 +00:00
|
|
|
bash stipple_gen.sh \
|
2021-09-10 04:37:08 +00:00
|
|
|
--display "false" \
|
2021-08-10 22:07:26 +00:00
|
|
|
--inputImage "${tmp}" \
|
|
|
|
--outputImage "${OUTPUT}/${name}_rendered.png" \
|
|
|
|
--outputSVG "${OUTPUT}/${name}.svg" \
|
|
|
|
--canvasWidth $WIDTH \
|
|
|
|
--canvasHeight $HEIGHT \
|
|
|
|
--dotSizeFactor $DOTSIZE \
|
|
|
|
--windowWidth $WIDTH \
|
|
|
|
--windowHeight $HEIGHT \
|
|
|
|
--maxGenerations $MAXGENERATIONS \
|
|
|
|
--minDotSize $MINDOTSIZE \
|
|
|
|
--line $LINE \
|
|
|
|
--fill $FILL \
|
2021-08-12 04:52:37 +00:00
|
|
|
--maxParticles $MAXPARTICLES \
|
2021-09-09 00:53:52 +00:00
|
|
|
--mode $MODE \
|
|
|
|
--invert $INVERT
|
2021-09-10 04:37:08 +00:00
|
|
|
|
2021-11-27 03:01:07 +00:00
|
|
|
if [[ "${INVERT}" != "false" ]]; then
|
2021-09-10 04:37:08 +00:00
|
|
|
convert "${OUTPUT}/${name}_rendered.png" -channel RGB -negate "${OUTPUT}/${name}_rendered.png"
|
|
|
|
fi
|
|
|
|
|
2021-08-10 22:07:26 +00:00
|
|
|
rm "${tmp}"
|
|
|
|
cd ~/src/animation/
|
2021-11-27 03:01:07 +00:00
|
|
|
|
2021-08-12 04:52:37 +00:00
|
|
|
if [ "${MODE}" != "tsp" ]; then
|
|
|
|
opt=`mktemp`.svg
|
|
|
|
svgsort "${OUTPUT}/${name}.svg" "${opt}"
|
|
|
|
mv "${opt}" "${OUTPUT}/${name}.svg"
|
|
|
|
fi
|
2021-08-10 23:36:54 +00:00
|
|
|
done
|
|
|
|
|
2021-09-16 14:42:59 +00:00
|
|
|
ffmpeg -y -r ${FRAMERATE} -f image2 -i "${IMAGES}" \
|
2021-08-12 04:52:37 +00:00
|
|
|
-c:v prores_ks -profile:v 3 \
|
|
|
|
"${VIDEO}"
|