tic

clear M;

num_frames = 60;

t_step = 1 / (num_frames - 1);


% generate a smoother parameter transition
ts = -5 : 10/(num_frames - 1) : 5;
st = atan(ts);
st = st - min(st(:));
st = st / max(st(:));

frame_num = 1;

for t = 0 : t_step : 1
    fprintf('frame %i of %i...\n', frame_num, num_frames);
    im_zoomed = zoom2(im1, im2, zx, zy, lowest_dist_scale, st(frame_num), 1);
    im_zoomed = im2double(im_zoomed);
    im_zoomed(im_zoomed > 1) = 1;
    im_zoomed(im_zoomed < 0) = 0;
    M(frame_num) = im2frame(im_zoomed);
    frame_num = frame_num + 1;
end

num_fade_frames = 60;
t_step = -1 / (num_fade_frames - 1);

for t = 1 : t_step : 0
    fprintf('fading out frame %i of %i...\n', frame_num - num_frames, num_fade_frames);
    im_zoomed = zoom2(im1, im2, zx, zy, lowest_dist_scale, 1, t);
    im_zoomed = im2double(im_zoomed);
    im_zoomed(im_zoomed > 1) = 1;
    im_zoomed(im_zoomed < 0) = 0;
    M(frame_num) = im2frame(im_zoomed);
    frame_num = frame_num + 1;
end

% add a pause at the current image
fixedFrame = im2frame(im_zoomed);
for t = 1 : 60
    M(frame_num) = fixedFrame;
    frame_num = frame_num + 1;
end



toc