function rotating_line_sections()
% source code for drawing a GIF
%
% 2017-09-16 Jahobr
[pathstr,fname] = fileparts(which(mfilename)); % save files under the same name and at file location
figHandle = figure(15674455);
clf
axesHandle = axes;
hold(axesHandle,'on')
set(figHandle, 'Units','pixel');
set(figHandle, 'position',[1 1 700 700]); % big start image for antialiasing later [x y width hight]
set(axesHandle,'position',[-0.06 -0.06 1.12 1.12]); % stretch axis bigger as figure, easy way to get rid of ticks [x y width height]
set(figHandle,'GraphicsSmoothing','on') % requires at least version 2014b
axis equal; drawnow;
nRings = 30;
% % % variants
% offset = zeros(1,30);
% offset = rand(1,30)*pi;
% offset = ones(1,30)*0.5;
offset = linspace(0,2,nRings);
% offset = log(linspace(1,7,30));
% offset = linspace(0,1,30).^2;
xlim([-35 35]); % default
ylim([-35 35]); % default
nFrames = 100;
angleP = -linspace(0,pi*2,nFrames+1); % define gear position in frames
angleP = angleP(1:end-1); % remove last frame, it would be double
for iFrame = 1:nFrames
cla(axesHandle) % fresh frame
for iRings = 1:nRings
ang = linspace(0,pi*2,iRings+1); % define gear position in frames
for iSection = 1:iRings
wedge = linspace(0,pi/iRings,22); % define gear position in frames
[X,Y] = pol2cart(wedge +offset(iRings)+angleP(iFrame)/iRings + ang(iSection),iRings*ones(1,22));
plot(X,Y,'k-','linewidth',7)
end
end
%% save animation
drawnow
% pause(0.01)
f = getframe(figHandle);
if iFrame == 1 % create colormap
map = gray(8); % create own color map %
im = rgb2ind(f.cdata,map,'nodither'); %
im(1,1,1,nFrames) = 0; % allocate
else
imtemp = rgb2ind(f.cdata,map,'nodither');
im(:,:,1,iFrame) = imtemp;
end
end
imwrite(im,map,fullfile(pathstr, [fname '.gif']),'DelayTime',1/30,'LoopCount',inf) % save gif
disp([fname '.gif has ' num2str(numel(im)/10^6 ,4) ' Megapixels']) % Category:Animated GIF files exceeding the 50 MP limit