function AllCoords_DisplayGifParticles(ScriptVar, AllCoords,...
    filename, RequiredFrames, ColourChoice, TransparencyArray)
    % Output - GIF of frames/.fig file for one frame; file saved in pwd
    % Inputs - 
    %    ScriptVar - Parameters container map
    %    AllCoords - Particle coordinates across all frames
    %    filename - string
    %    RequiredFrames - 1x2 array
    %                     [4 8] - make GIF of frames 4 to 8
    %                     [4 4] - make FIG file for frame 4
    %    
    % Optional Inputs - ignore if particles of only one type used
    %    Colour palette choice - only two options:
    %                   i) 'rgm' => 'red','green','magenta'
    %                   ii) 'default' => default colour order
    %    Transparency array - 1xN array of 0-1 values, where N = number of particle types
    %                     [1 1 1] => Opacity for all three particle types in 
    %                     a 3-particle-type-comprising simulation
    %                     1 =?
    %                     [1 0] => Hide all particles of the second type
    %                     (in a two-particle-type simulation)
    %          
    % Usage - 
    %    AllCoords_DisplayGifParticles(ScriptVar, AllCoords,'tryoutput', [1 100])
    %    AllCoords_DisplayGifParticles(ScriptVar, AllCoords,'trydiffoutput', [50 50])
    % 
    %    AllCoords_DisplayGifParticles(ScriptVar, AllCoords, 'trytrial3',...
    %    'sample_simulation_run',[16 25],'rgm')
    
    %% Set colour order
    if ~exist('ColourChoice','var')
        ColourChoice = 'default';
    end
    if strcmpi(ColourChoice, 'rgm') % Set colour order for plotting particle types
        ColourArray = {'r','g','m'};
        disp('Using red-green-magenta colour order')
    else
        ColourArray = {[0,0.447,0.741], [0.85,0.325,0.098], [0.929,0.694,0.125],...
                        [0.494,0.184,0.556], [0.466,0.674,0.188], [0.301,0.745,0.933],...
                        [0.635,0.078,0.184]};
        disp('Using default colour order')
    end
    
    %% Set viscous zones if they exist
    if ScriptVar('N_FramesRegion') > 0  % Otherwise, no viscous region(s)
        xyHoney = ScriptVar('xyHoney');
    end
    
    %% Set FRAP region (if simulation has a FRAP event)
    if isKey(ScriptVar, 'xyFRAPRegion') % If this is a FRAP simulation
        FRAP = true;
        xyFRAPRegion = ScriptVar('xyFRAPRegion'); % Set xyFRAPRegion
    else
        FRAP = false;
    end
    
    %% Set transparency of particles in the figure, if not provided as an optional input
    if ~exist('TransparencyArray','var')
        TransparencyArray = ones(size(ScriptVar('N_Particles')));
    end
    
    %% Create plotting objects for xyStartFigure, xyHoney and xyFRAPRegion
    xyStartFigure = ScriptVar('xyStartFigure');
    posStartFigure = cell(size(xyStartFigure));
    for i = 1:length(xyStartFigure)
        if length(xyStartFigure{i}) == 3
            posStartFigure{i} = [xyStartFigure{i}(1) - xyStartFigure{i}(3),...
                              xyStartFigure{i}(2) - xyStartFigure{i}(3),...
                              2*xyStartFigure{i}(3),...
                              2*xyStartFigure{i}(3)];
        else
            posStartFigure{i} = 0;
        end
    end
    % posStartFigure is used to plot xyStartFigure zones
    
    if ScriptVar('N_FramesRegion') > 0
        posHoney = cell(size(xyHoney));
        for i = 1:length(xyHoney)
            if length(xyHoney{i}) == 3
                posHoney{i} = [xyHoney{i}(1) - xyHoney{i}(3),...
                            xyHoney{i}(2) - xyHoney{i}(3),...
                            2*xyHoney{i}(3),...
                            2*xyHoney{i}(3)];
                %CircleHoney = [xyHoney(3) * cos(0:pi/50:2*pi) + xyHoney(1),...
                %                xyHoney(3) * sin(0:pi/50:2*pi) + xyHoney(2)];
            end
        end
    end
    % posHoney is used to plot xyHoney zones
    
    if FRAP
        xyFRAPRegion = xyFRAPRegion{1};
        if length(xyFRAPRegion) == 3 % circular ROI
            posFRAPSpot = [xyFRAPRegion(1) - xyFRAPRegion(3),...
                              xyFRAPRegion(2) - xyFRAPRegion(3),...
                              2*xyFRAPRegion(3),2*xyFRAPRegion(3)];
            FRAPROIShape = 'circle';
        else % rectangular ROI
            posFRAPSpot = xyFRAPRegion;
            FRAPROIShape = 'rect';
        end
    end
    % posFRAPSpot is used to plot the FRAP ROI
    
    %% Set filename
    if RequiredFrames(1) > RequiredFrames(2)
        error('Error. End frame should be equal or larger than start frame.')
    end
    if RequiredFrames(1) ~= RequiredFrames(2)
        filename = strcat(filename, '.gif');
    else
        filename = strcat(filename, '.fig');
    end
    
    %% Create figure object
    figure; clf;
    if ~FRAP
        set(gcf,'Position',[435.4 245.8 667 347])
        %set(gcf,'Position',[816   865   668   700]);
    else % Figure is taller if FRAP keeping in mind that viscous granules
         % appear circular if they are present
        set(gcf,'Position',[435.4 245.8 700 347])
        %set(gcf,'Position',[816   865   700   700]);
    end
    
    %% Start plotting
    counter = 1; % Used to distinguish first frame in a GIF from subsequent ones
    movegui('center')
    
    N_Particles = ScriptVar('N_Particles');
    
    %% Iterate through all frames (or one frame in case no GIF)
    for i = RequiredFrames(1):RequiredFrames(2)
        %% Plot particles
        a = AllCoords(1:N_Particles(1),:,i);
        if FRAP
            % Plot bleached, non-bleached particles separately
            a_notFRAP =  a(a(:,3)==0,:); %a(:, FRAP_indices==0);
            a_FRAP = a(a(:,3)==1,:);     %a(:, FRAP_indices==1);
            scatter(a_notFRAP(:,1), a_notFRAP(:,2), 3, ColourArray{1}, 'filled',...
            'MarkerFaceAlpha', TransparencyArray(1),...
            'MarkerEdgeAlpha', TransparencyArray(1));
            hold on
            scatter(a_FRAP(:,1), a_FRAP(:,2), 3, 'black', 'filled',...
            'MarkerFaceAlpha', TransparencyArray(1),...
            'MarkerEdgeAlpha', TransparencyArray(1));
            
            % Plot other particle types
            for j = 2:length(N_Particles)
                StartIndex = sum(N_Particles(1:j-1));
                a = AllCoords(StartIndex+1:StartIndex+N_Particles(j),:,i);
                a_notFRAP =  a(a(:,3)==0,:); %a(:, FRAP_indices==0);
                a_FRAP = a(a(:,3)==1,:);     %a(:, FRAP_indices==1);
                scatter(a_notFRAP(:,1), a_notFRAP(:,2), 3, ColourArray{j}, 'filled',...
                'MarkerFaceAlpha', TransparencyArray(j),...
                'MarkerEdgeAlpha', TransparencyArray(j));
                    
                scatter(a_FRAP(:,1), a_FRAP(:,2), 3, 'black', 'filled',...
                'MarkerFaceAlpha', TransparencyArray(j),...
                'MarkerEdgeAlpha', TransparencyArray(j));
            end
        else
            scatter(a(:,1), a(:,2), 3, ColourArray{1}, 'filled',...
            'MarkerFaceAlpha', TransparencyArray(1),...
            'MarkerEdgeAlpha', TransparencyArray(1));
            hold on
            
            % Plot other particle types
            for j = 2:length(N_Particles)
                StartIndex = sum(N_Particles(1:j-1));
                a = AllCoords(StartIndex+1:StartIndex+N_Particles(j),:,i);
                scatter(a(:,1), a(:,2), 3, ColourArray{j}, 'filled',...
                'MarkerFaceAlpha', TransparencyArray(j),...
                'MarkerEdgeAlpha', TransparencyArray(j));
            end
        end
        
        %% Set axes limits, labels, title and plot bounding box/H-Box
        xlim([0 ScriptVar('xLimit')]);
        ylim([0 ScriptVar('yLimit')]);
        xlabel('$x\ (\mu m)$','Interpreter','LaTeX')
        ylabel('$y\ (\mu m)$','Interpreter','LaTeX')

        title(['Frame = ' num2str(i)]);
        
        if ~isKey(ScriptVar, 'OverallBoundaries')
            box on
        else
            plot(OverallBoundariesShape,'LineWidth',0.5,'FaceColor','None');
        end
        
        %% Plot initialisation zone (xyStartFigure), viscous zone (xyHoney)
        if i <= ScriptVar('N_FramesStartBoundaries')
            for ii = 1:length(xyStartFigure)
                if length(xyStartFigure{ii}) >= 5 % polygon
                    xvStart = xyStartFigure{ii}(:,1);
                    yvStart = xyStartFigure{ii}(:,2);
                    pgon = polyshape(xvStart, yvStart);
                    plot(pgon, 'FaceColor', 'none');
                elseif length(xyStartFigure{ii}) == 4 % rectangle
                    p = xyStartFigure{ii};
                    xvStart = [ p(1) p(1) p(1)+p(3) p(1)+p(3) ];
                    yvStart = [ p(2) p(2)+p(4) p(2)+p(4) p(2) ];
                    pgon = polyshape(xvStart, yvStart);
                    plot(pgon, 'FaceColor', 'none');
                else % circle
                    rectangle('Position',posStartFigure{ii},'Curvature',[1 1],...
                        'FaceColor', 'None')
                end
            end
        end
            
        if i <= ScriptVar('N_FramesRegion')
            for ii = 1:length(xyHoney)
                if length(xyHoney{ii}) >= 5 % polygon
                    xvStart = xyHoney{ii}(:,1);
                    yvStart = xyHoney{ii}(:,2);
                    pgon = polyshape(xvStart, yvStart);
                    plot(pgon, 'LineStyle', '--', 'FaceColor', [1 0 0 0.2]);
                elseif length(xyHoney{ii}) == 4 % rectangle
                    p = xyHoney{ii};
                    xvStart = [ p(1) p(1) p(1)+p(3) p(1)+p(3) ];
                    yvStart = [ p(2) p(2)+p(4) p(2)+p(4) p(2) ];
                    pgon = polyshape(xvStart, yvStart);
                    plot(pgon, 'LineStyle', '--', 'FaceColor', [1 0 0 0.2]);
                else % circle
                    rectangle('Position',posHoney{ii},'Curvature',[1 1], ...
                        'LineStyle', '--', 'FaceColor', [1 0 0 0.2]);
                end
            end
        end
        
        %% Plot FRAP ROI if simulation has a FRAP event
        if FRAP
            if i >= ScriptVar('FRAP_bleaching_frame')
                if strcmpi(FRAPROIShape,'circle')
                    rectangle('Position',posFRAPSpot,'Curvature',[1 1],...
                        'FaceColor', 'None')
                elseif strcmpi(FRAPROIShape,'rect')
                    rectangle('Position',posFRAPSpot,...
                        'FaceColor', 'None')
                end
            end
        end
        set(findall(gcf,'-property','FontSize'),'FontSize',20)
        %% Make GIF else make figure
        if RequiredFrames(1) ~= RequiredFrames(2)
            hold off
            drawnow;
            
            frame_time=.005;
            frame = getframe(gcf);
            im = frame2im(frame);
            [A,map] = rgb2ind(im,256);
            if counter == 1
                imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',1);
            else
                imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',frame_time);
            end
            counter = counter + 1;
        else
            hold off
            savefig(filename)
        end
    end
end