Skip to content
Snippets Groups Projects
Select Git revision
  • fe4b6c99a75a913d7f3d28adc584227be2ad5161
  • master default protected
  • v1.2.12
  • ctc2019
  • v1.1.11
  • v1.1.10
  • v1.1.8
  • v1.1.4
  • v1.0.9
  • v1.0.3
  • v1.0.2
11 results

goFigureAnimation.m

Blame
  • user avatar
    la_29 authored
    fe4b6c99
    History
    goFigureAnimation.m 1.82 KiB
    % this code can be functionalized
    % can also add features:
    % periodicity toggle? if true remove final frame
    % changing number of inbetweens to speed up or slow down the animation
    
    fileName = 'ssfClustering';              % name of movie generated
    frameRate = 30;                          % desired frame rate
    duration = 30;                           % desired length of movie in seconds
    azimuthList = [-20,-110,-190,-290,-380]; % camera pan angle at key frames
    elevationList = [10,10,10,10,10];        % camera tilt angle at key frames
    
    v = VideoWriter(fileName,'MPEG-4');
    v.FrameRate = frameRate;
    open(v);
    
    % interpolate viewing angles between key frames to match the specified duration
    
    keyFrameList = [azimuthList;elevationList]';
    numFrames = round(duration * frameRate);
    intervalLength = (numFrames - 1) / (size(keyFrameList,1) - 1);
    
    % initialize the angleList
    angleList = zeros(numFrames,2);
    
    for numKeyFrame = 1:size(keyFrameList,1) - 1
        
        firstRow = round(intervalLength * (numKeyFrame - 1) + 1); % first row of the interval between key frames
        lastRow = round(intervalLength * numKeyFrame + 1);        % last row of the interval between key frames
        
        a = keyFrameList(numKeyFrame,1);     % initial key frame azimuth angle
        b = keyFrameList(numKeyFrame + 1,1); % ending key frame azimuth angle
        
        c = keyFrameList(numKeyFrame,2);     % initial key frame elevation angle
        d = keyFrameList(numKeyFrame + 1,2); % ending key frame elevation angle
        
        n = round(intervalLength * numKeyFrame) - round(intervalLength * (numKeyFrame - 1)) + 1; % number of angles to add 
        
        angleList(firstRow:lastRow,:) = [linspace(a,b,n).' , linspace(c,d,n).'];
        
    end
    
    % capture frames and write to the movie file
    for frame = 1:size(angleList,1)
        view(angleList(frame,:));
        drawnow;
        writeVideo(v,getframe(gcf));
    end
    
    close(v);