1######################################################################## 2## 3## Copyright (C) 1999-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {@var{map} =} prism () 28## @deftypefnx {} {@var{map} =} prism (@var{n}) 29## Create color colormap. This colormap cycles through red, orange, yellow, 30## green, blue and violet with each index change. 31## 32## The argument @var{n} must be a scalar. 33## If unspecified, the length of the current colormap, or 64, is used. 34## @seealso{colormap} 35## @end deftypefn 36 37function map = prism (n) 38 39 if (nargin > 1) 40 print_usage (); 41 elseif (nargin == 1) 42 if (! isscalar (n)) 43 error ("prism: N must be a scalar"); 44 endif 45 n = double (n); 46 else 47 hf = get (0, "currentfigure"); 48 if (! isempty (hf)) 49 n = rows (get (hf, "colormap")); 50 else 51 n = 64; 52 endif 53 endif 54 if (n == 1) 55 map = [1 0 0]; 56 elseif (n > 1) 57 C = [1, 0, 0; 1, 1/2, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 2/3, 0, 1]; 58 map = C(rem (0:(n-1), 6) + 1, :); 59 else 60 map = zeros (0, 3); 61 endif 62 63endfunction 64 65 66%!demo 67%! ## Show the 'prism' colormap profile and as an image 68%! cmap = prism (18); # 6 colors, therefore cycle 3 times 69%! subplot (2, 1, 1); 70%! rgbplot (cmap, "composite"); 71%! subplot (2, 1, 2); 72%! rgbplot (cmap); 73