function spinmap(time,inc)
%SPINMAP Spin color map.
%   SPINMAP cyclically rotates the color map for about 3 seconds.
%   SPINMAP(T) rotates it for about T seconds.
%   SPINMAP(inf) is an infinite loop, break with <ctrl-C>.
%   SPINMAP(T,inc) uses the specified increment.  The default is
%   inc = 2, so inc = 1 is a slower rotation, inc = 3 is faster,
%   inc = -2 is the other direction, etc.
%
%   To avoid multiple redraws, set(gcf,'sharecolors','off') and
%   set(gcf,'renderer','painters').
%
%   SPINMAP only works on 256 color screens.
%
%   See also COLORMAP, RGBPLOT.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 5.9 $  $Date: 2000/06/02 04:30:53 $

if nargin < 1, time = 3; end
if nargin < 2, inc = 2; end

cm = colormap;
M = cm;

sh = get(gcf,'sharecolors');
renmode = get(gcf,'rendererMode');
ren = get(gcf,'renderer');
if get(0,'screendepth') ~= 8,
  warning('Colormap animation is only possible for 256 color screens.');
  return
end
set(gcf,'sharecolors','off','renderer','painters')
drawnow

% Generate the rotated index vector; allow for negative inc.
m = size(M,1);
k = rem((m:2*m-1)+inc,m) + 1;

% Use while loop because time might be inf.
t = clock;
while etime(clock, t) < time
   M = M(k,:);
   colormap(M)
end

colormap(cm)
set(gcf,'sharecolors',sh)
if strcmp(renmode,'auto')
  set(gcf,'renderermode','auto')
else
  set(gcf,'renderer',ren)
end
