#!/bin/bash

set -e
source ./configuration.sh

SEQUENCES=" slices sculpt al sandal power_lines cessna magnolia"

IDX=0

# -----------------------------------------
introduction ()
{
simg="WS/fond-introduction.png"
dimg="LF/titre-introduction.png"

echo 'making' $dimg 'now...'

convert	$simg				\
	-alpha off			\
	-font ${TEXT_BF}		\
	-fill Orange			\
	-stroke Yellow			\
	-strokewidth 2			\
	-pointsize 160			\
	-kerning 10			\
	-gravity Center			\
	-annotate +0+0 "Wireframes"	\
	$dimg

for foo in $(seq 0 90)
do
	lname=$(printf "%s/%s/%05d.png" $PWD "LF" $IDX)
	IDX=$(( IDX + 1 ))
	ln -s  $PWD/$dimg $lname 
	echo $? $lname
done

}

# -----------------------------------------
intertitre ()
{
simg="WS/fond-intertitre.png"
dimg="LF/it-"$1".png"

echo $dimg

convert	$simg				\
	-alpha off			\
	-font ${TEXT_BF}		\
	-fill Orange			\
	-stroke Yellow			\
	-strokewidth 2			\
	-pointsize 120			\
	-kerning 40			\
	-gravity Center			\
	-annotate +0+0 $1		\
	$dimg

for foo in $(seq 0 80)
do
	lname=$(printf "%s/%s/%05d.png" $PWD "LF" $IDX)
	# echo "linkname =" $lname
	IDX=$(( IDX + 1 ))
	ln -s  $PWD/$dimg $lname 
done
echo "intertitre" $1 "  [done]"
}
# -----------------------------------------
action ()
{
sdir="frames/"$1"/"

echo '+++++++++++++ ' $sdir

intertitre $1

for img in $(ls -1 ${PWD}/${sdir}*.png)
do
	lname=$(printf "%s/%s/%05d.png" $PWD "LF" $IDX)
	# echo "img=       " $img
	# echo "linkname=  " $lname
	IDX=$(( IDX + 1 ))

	ln -s  $img $lname 

done

echo $1 "[done]  at " $IDX
}
# -----------------------------------------

introduction "FOO.OBJ"

for seq in $SEQUENCES
do

	action $seq ; echo
	sleep 10

done

intertitre "End"

# -----------------------------------------

ffmpeg  -nostdin                                                \
        -loglevel error                                         \
        -y -r 30 -f image2 -i LF/%05d.png			\
	-metadata artist='---[ tTh ]---'			\
	-metadata title='* OBJ file experiments *'		\
 	-preset veryslow					\
        -c:v libx264 -pix_fmt yuv420p                           \
        the-movie.mp4
