From a337fc0d8b35a8082730a5218e944713d219f0b3 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Wed, 12 Oct 2022 13:37:13 -0400 Subject: [PATCH] Silly hack to get svgopt to run without erroring out. --- for.sh | 44 +++++++++++++++ seq.sh | 2 +- stipple.sh | 5 +- stipple_sine.sh | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 for.sh create mode 100644 stipple_sine.sh diff --git a/for.sh b/for.sh new file mode 100644 index 0000000..4160546 --- /dev/null +++ b/for.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +LAST=$1 + +PI=3.14159265359 +FPS=24 +MULTIPLE=3 +STEP=$(echo "scale=6;360/45" | bc -l) +AMP=1.0 +STARTANGLE=270 + +DOTSIZE_MIN=2 +DOTSIZE_MAX=6 +DOTSIZE_HALF=`echo "scale=6;($DOTSIZE_MAX - $DOTSIZE_MIN) / 2" | bc` +DOTSIZE=`echo "scale=6;($DOTSIZE_MIN + $DOTSIZE_HALF)" | bc` +DOTSIZE_MULTIPLE=$DOTSIZE_HALF + +PARTICLES_MIN=300 +PARTICLES_MAX=550 +PARTICLES_HALF=`echo "($PARTICLES_MAX - $PARTICLES_MIN) / 2" | bc` +PARTICLES=$((PARTICLES_MIN+PARTICLES_HALF)) +PARTICLES_MULTIPLE=$PARTICLES_HALF + +fluctuation () { + i=$1 + ANGLE=$(echo "scale=6;$STARTANGLE+($i * $STEP)" | bc) + FLUCTUATION=$(echo "scale=6;s($ANGLE*($PI/180))*$AMP" | bc -l) + echo $FLUCTUATION +} + +i=0 + +while [ $i -lt $LAST ]; do + FLUCTUATION=$(fluctuation $i) + REALTIME=$(echo "scale=1;($i*$MULTIPLE)/$FPS" | bc -l) + echo "[${i}] $((i*MULTIPLE)) $REALTIME: ${FLUCTUATION}" + fluc=`fluctuation $i` + particles=`echo "scale=0;($PARTICLES-($fluc*$PARTICLES_MULTIPLE))/1" | bc` + dotsize=`echo "scale=6;$DOTSIZE+($fluc*$DOTSIZE_MULTIPLE)" | bc` + echo $fluc + echo $particles + echo $dotsize + i=$((i+1)) +done \ No newline at end of file diff --git a/seq.sh b/seq.sh index 54901da..a7f1448 100644 --- a/seq.sh +++ b/seq.sh @@ -7,7 +7,7 @@ # ########################### -MULTIPLE=3 +MULTIPLE=2 FPS=24 RATE=`echo "scale=0;${FPS}/${MULTIPLE}" | bc` TIMESTR="" diff --git a/stipple.sh b/stipple.sh index e947966..3e37279 100644 --- a/stipple.sh +++ b/stipple.sh @@ -25,7 +25,7 @@ fi mkdir -p "${OUTPUT}" -MULTIPLE=3 +MULTIPLE=2 FPS=24 RATE=`echo "scale=0;${FPS}/${MULTIPLE}" | bc` @@ -74,7 +74,10 @@ stipple () { if [ "${MODE}" != "tsp" ]; then opt=`mktemp`.svg + CURRENT=$(pwd) + cd / svgsort "${OUTPUT}/${name}.svg" "${opt}" + cd $CURRENT mv "${opt}" "${OUTPUT}/${name}.svg" fi } diff --git a/stipple_sine.sh b/stipple_sine.sh new file mode 100644 index 0000000..adf107c --- /dev/null +++ b/stipple_sine.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +########################### +# +# Run the stipple_gen script on a sequence +# of PNG images and then render the resulting +# preview images into a video. Fluctuate settings +# via a sine wave. +# +########################### + +if [[ "${1}" == "" ]]; then + echo "Please provide a directory of images as the first argument" + exit 1 +fi + +INPUT=`realpath "${1}"` +OUTPUT=`realpath "${2}"` +CONFIG="${3}" +SINGLE="${4}" + +if [ ! -d "${INPUT}" ]; then + echo "Directory ${1} doesn't exist" + exit 2 +fi + +mkdir -p "${OUTPUT}" + +PI=3.14159265359 +FPS=24 +MULTIPLE=2 +STEP=$(echo "scale=6;360/45" | bc -l) +AMP=1.0 +STARTANGLE=270 + +RATE=`echo "scale=0;${FPS}/${MULTIPLE}" | bc` + +WIDTH=404 +HEIGHT=374 + +DOTSIZE_MIN=1.8 +DOTSIZE_MAX=6 +DOTSIZE_HALF=`echo "scale=6;($DOTSIZE_MAX - $DOTSIZE_MIN) / 2" | bc` +DOTSIZE=`echo "scale=6;($DOTSIZE_MIN + $DOTSIZE_HALF)" | bc` +DOTSIZE_MULTIPLE=$DOTSIZE_HALF +PARTICLES_MIN=300 +PARTICLES_MAX=650 +PARTICLES_HALF=`echo "($PARTICLES_MAX - $PARTICLES_MIN) / 2" | bc` +PARTICLES=$((PARTICLES_MIN+PARTICLES_HALF)) +PARTICLES_MULTIPLE=$PARTICLES_HALF + +if [[ "${CONFIG}" == "" ]]; then + echo "Please provide a config file" + exit 1 +fi + +IMAGES="" + +fluctuation () { + i=$1 + ANGLE=$(echo "scale=6;$STARTANGLE+($i * $STEP)" | bc) + FLUCTUATION=$(echo "scale=6;s($ANGLE*($PI/180))*$AMP" | bc -l) + echo $FLUCTUATION +} + +stipple () { + png="${1}" + frame="${2}" + filename=`basename "${png}"` + name=`echo "${filename}" | cut -d'.' -f1` + num=`echo "${name}" | awk -F'_' '{print $(NF)}'` + tmp=`mktemp`.png + fluc=`fluctuation $frame` + particles=`echo "scale=0;($PARTICLES-($fluc*$PARTICLES_MULTIPLE))/1" | bc` + dotsize=`echo "scale=6;$DOTSIZE+($fluc*$DOTSIZE_MULTIPLE)" | bc` + #echo $fluc + echo "maxParticles: $particles" + echo "dotSizeFactor: $dotsize" + + bash white.sh "${png}" "${tmp}" + + source "${CONFIG}" + + cd ~/src/stipple_gen/ + bash stipple_gen.sh \ + --inputImage "${tmp}" \ + --outputImage "${OUTPUT}/${name}_rendered.png" \ + --outputSVG "${OUTPUT}/${name}.svg" \ + --config "${CONFIG}" \ + --dotSizeFactor $dotsize \ + --maxParticles $particles + + if [[ "${invert}" == "true" ]]; then + convert "${OUTPUT}/${name}_rendered.png" -channel RGB -negate "${OUTPUT}/${name}_rendered.png" + fi + + rm "${tmp}" + cd ~/src/animation/ + + if [ "${MODE}" != "tsp" ]; then + opt=`mktemp`.svg + CURRENT=$(pwd) + cd / + svgsort "${OUTPUT}/${name}.svg" "${opt}" + cd $CURRENT + mv "${opt}" "${OUTPUT}/${name}.svg" + fi +} + +if [[ "${SINGLE}" != "" ]]; then + i=0; + echo "Rendering a single frame, #${SINGLE}" + #files in dir + for png in "${INPUT}/"*.png ; do + if [[ ${i} -eq ${SINGLE} ]]; then + stipple "${png}" ${i} + break + fi + i=$((i+1)) + done + + exit +fi + +i=0; +#files in dir +for png in "${INPUT}/"*.png ; do + stipple "${png}" ${i} + i=$((i+1)) +done + +if [[ "${IMAGES}" == "" ]]; then + part=`echo "${name}" | awk -F'_0' '{print $1}'` + IMAGES="${OUTPUT}/${part}_%06d_rendered.png" + VIDEO="${OUTPUT}/${part}.mov" +fi + +ffmpeg -y -r ${RATE} -f image2 -i "${IMAGES}" \ + -r ${FPS} \ + -c:v prores_ks -profile:v 3 \ + "${VIDEO}"