home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / COLOR.DI$ / PRISM.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.3 KB  |  47 lines

  1. function map = prism(m)
  2. %PRISM    Colormap of prism colors.
  3. %    PRISM(M) returns an M-by-3 matrix containing repeated use
  4. %    of six colors: red, orange, yellow, green, blue, violet.
  5. %    The default value of M is the length of the current colormap.
  6. %
  7. %    PRISM, with no input or output arguments, changes the colors
  8. %    of any line objects in the current axes to the prism colors.
  9. %    This is particularly useful with a CONTOUR plot, eg.
  10. %        contour(data,20)
  11. %        prism
  12. %
  13. %    The colors in the PRISM map are also present, in the same order,
  14. %    in the HSV map.  However, PRISM uses repeated copies of its six
  15. %    colors, whereas HSV varies its colors smoothly.
  16. %
  17. %    See also HSV, FLAG, HOT, COOL, COLORMAP, RGBPLOT, CONTOUR.
  18.  
  19. %    C. Moler, 8-11-92.
  20. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  21.  
  22. if nargin + nargout == 0
  23.    h = get(gca,'child');
  24.    m = length(h);
  25. elseif nargin == 0
  26.    m = size(get(gcf,'colormap'),1);
  27. end
  28.  
  29. % R = [red; orange; yellow; green; blue; violet]
  30. R = [1 0 0; 1 1/2 0; 1 1 0; 0 1 0; 0 0 1; 2/3 0 1];
  31.  
  32. % Generate m/6 vertically stacked copies of r with Kronecker product.
  33. e = ones(ceil(m/6),1);
  34. R = kron(e,R);
  35. R = R(1:m,:);
  36.  
  37. if nargin + nargout == 0
  38.    % Apply to lines in current axes.
  39.    for k = 1:m
  40.       if strcmp(get(h(k),'type'),'line')
  41.          set(h(k),'color',R(k,:))
  42.       end
  43.    end
  44. else
  45.    map = R;
  46. end
  47.