#!/bin/bash
# evo.sh is a script
# supporting the production of generated art,
# using the tool evolvotron by Tim Day.
# http://www.timday.com/share/evolvotron/index.htm
#
# André Plümer genannt Woistpeter | free@apgw.de
# copyleft 2020

#set -x

# First step / run:
# Let evolvotron generate images
# with "evo.sh 5", 5 images
# plus a XML-file with all values
# for the generating evolvotrun-functions
# are created.
if [[ $1 =~ [0-9] ]]; then
	redo=$1
	echo "will generate $1 image[s]"
else
	redo=1
fi

if [[ ! $1 =~ [a-z] ]]; then
for i in $(seq 1 $redo); do
	stamp=$(date +%s)
	echo "step $i ... processing ${stamp}_evoerg.png"
	evolvotron_mutate -g | tee ${stamp}_func.xml | evolvotron_render -s 1920x1080 ${stamp}_evoerg.png
done

# Second step / run:
# After you possibly manually decided
# wich imges you like and keep,
# and you have deleted images + XML
# you don't like,
# you can use all images in that folder
# as new input for evolvitron mutations:
# "evo.sh m"
elif [[ $1 == "m" ]]; then
	echo "mutation mode"
	for func in *.xml; do
		stamp=$(date +%s)
		echo "step $i ... processing ${stamp}_evoerg.png"
		evolvotron_mutate < $func | tee ${stamp}_func.xml | evolvotron_render -s 1920x1080 ${stamp}_evoerg.png
	done
fi

#set +x
