#!/bin/bash
#A gnuplot animation

which gnuplot &> /dev/null

if [ "$?" -ne "0" ]
then
	echo "You must have gnuplot installed"
	exit 1
fi



echo "Writing the launch script for gnuplot in ganim_launch.gp..."

echo "i=0" 			> ganim_launch.gp
echo "set polar" 		>> ganim_launch.gp
echo "set xrange [-5:5]" 	>> ganim_launch.gp
echo "set yrange [-5:5]" 	>> ganim_launch.gp
echo "load \"ganim_script.gp\"" >> ganim_launch.gp

echo "This is the written file:"
echo "---"
cat ganim_launch.gp
echo "---"

echo "Writing the main gnuplot script in ganim_script.gp..."

echo "plot exp(sin(t)) - 2* cos(i*t) + (sin(1/2*(i*t - pi)))" > ganim_script.gp
echo "i=i+0.1"						      >> ganim_script.gp
echo "pause 0.05"					      >> ganim_script.gp
echo "if(i < 1000) reread"				      >> ganim_script.gp

echo "This is the written file:"
echo "---"
cat ganim_script.gp
echo "---"

echo "Ok, waiting 2 seconds and then launching \"gnuplot ganim_launch.gp\""
echo "To stop the animation hit CTRL+C in the terminal"
echo "Now, Enjoy ^_^"
sleep 2
gnuplot ganim_launch.gp
