%% initialization
dur = 20;
fs  = 10;
constvel  = 0;
NumSpokes = 3;

tt=0:1/fs:dur;

%% construct phasor (for 2 different cases)
if (constvel)
    % constant velocity rotation
    vv = 4.5;
    phi = 2*pi*vv*tt;
else
    % constant acceleration
    aa = 0.5;
    phi = 2*pi*aa*tt.^2/2;
end

phasor = exp(j*phi);

%% prep figure
cc = cos(0:0.01:2*pi);
ss = sin(0:0.01:2*pi);
fig=figure(1);
set(fig,'DoubleBuffer','on');
plot( cc, ss, 'b-' );

%% animation
for kk = 1:length(tt)
   tic
   plot( cc, ss, 'b');
   hold on
   
   for jj =1:NumSpokes
       SpokeOffset = exp(j*(jj-1)*2*pi/NumSpokes);
       pp = phasor(kk)*SpokeOffset;
       xx = [0 real(pp)];
       yy = [0 imag(pp)];
       plot( xx, yy, 'r-', real(pp), imag(pp), 'ro');
   end
   
   set(gca,'xlim',[-1.2 1.2],'ylim',[-1.2 1.2]);
   axis('equal');
   grid on;
   
   hold off
   
   if (constvel)
       msg = sprintf('%2.1f rps', vv);
   else
       msg = sprintf('%2.1f rps', aa*tt(kk));
   end
   text(1,1,msg);
   
   remaining = 1/fs-toc;
   if ( remaining > 0 )
       pause( remaining );
   else
       disp('unable to maintain fram rate');
   end
end