#!/bin/bash

source ./configuration.sh

POVOPT=" -d +q9 +a +W600 +H800 -v +WT2"
DDIR="frames/sculpture"
PASS=80
NBFRAMES=360

STDERR="WS/sculpt.stderr"
TMPIMG="/dev/shm/tmpsculpt.png"
LAST="WS/sculpt.last"

if [ ! -r $LAST ] 
then
	echo 0 >  $LAST
fi

for pass in $(seq 0 $PASS)
do

	idx=$(cat $LAST)
	next=$(( ( idx + 1 ) % NBFRAMES ))

	outfile=$(printf "%s/%04d.png" $DDIR $idx ) 
	echo $pass "/" $PASS " = " $outfile

	povray -isculpture.pov -K${idx} $POVOPT -O${TMPIMG}  2> $STDERR

	convert ${TMPIMG}				\
		-fill Gray20				\
		-pointsize 16				\
		-font ${TEXT_IT}			\
		-gravity South-West			\
		-annotate +15+10 "Konrad+tTh"		\
		$outfile

	echo '.' ; echo $next > $LAST

	sleep 52

done

ffmpeg  -nostdin                                                \
        -loglevel error                                         \
        -y -r 30 -f image2 -i $DDIR/%04d.png			\
	-metadata artist='---[ tTh ]---'			\
	-metadata title='* this is really a dirty loop *'	\
 	-preset veryslow					\
        -c:v libx264 -pix_fmt yuv420p                           \
        wtf.mp4

