% Evolve a gaussian wavepacket with c_g .ne. c  (no distortion effects
% included).  By Ian, quicktime movie generation lines added by Laure.  
% This script is also an example of using LaTeX commands in titles.

% When making a long animation, can use the following commands (bash):
% $ export DISPLAY=""
% $ echo " " > input
% $ nohup matlab -nodesktop -nosplash -nojvm -r ripples < input &> out.txt&

close all; clear all
LaTeX_title=0;

MakeQTMovie('start','Output/ripples.qt')

c=2;cg=1;k=8;sigma=1.4;
x=-10:0.1:10;
t=-8;
y=exp(-(x-cg*t).^2/sigma^2).*sin(k*(x-c*t));
h=plot(x,y); axis equal, set(gca,'XLim',[-10,10],'YLim',[-1 1])
%     ,sprintf('t=%5.2f, $$\\alpha$$',t)...
if LaTeX_title==1;
  text(-8,2 ...
       ,sprintf('$$t=%5.2f,\\ \\exp(-\\frac{(x-c_gt)^2}{\\sigma^2})\\ \\sin\\ k(x-ct)$$',t)...
       ,'interpreter','latex','FontSize',12);
end

for t=-8:0.03:8
  y=exp(-(x-cg*t).^2/sigma^2).*sin(k*(x-c*t));
  h=plot(x,y); axis equal, set(gca,'XLim',[-10,10],'YLim',[-1 1])
  if LaTeX_title==1;
    text(-8,2 ...
         ,sprintf('$$t=%5.2f,\\ \\exp\\ {-\\frac{(x-c_gt)^2}{\\sigma^2}}\\ \\sin\\ k(x-ct)$$',t)...
         ,'interpreter','latex','FontSize',12);
  end
  pause(0.05)
  set(gcf, 'PaperUnits', 'inches'); set(gcf, 'PaperSize', [5 1]);
  set(gcf, 'PaperPosition', [0 0 5 1]); %% [left, bottom, width, height];
  print('-djpeg','Output/tmp.jpg')
  MakeQTMovie('addimage','Output/tmp.jpg')
end
MakeQTMovie finish
