1######################################################################## 2## 3## Copyright (C) 1994-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} =} gray () 28## @deftypefnx {} {@var{map} =} gray (@var{n}) 29## Create gray colormap. This colormap varies from black to white with shades 30## of gray. 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 = gray (n) 38 39 if (nargin > 1) 40 print_usage (); 41 elseif (nargin == 1) 42 if (! isscalar (n)) 43 error ("gray: 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 55 if (n == 1) 56 map = [0, 0, 0]; 57 elseif (n > 1) 58 gr = [0:(n-1)]' / (n - 1); 59 map = [gr, gr, gr]; 60 else 61 map = zeros (0, 3); 62 endif 63 64endfunction 65 66 67%!demo 68%! ## Show the 'gray' colormap profile and as an image 69%! cmap = gray (16); 70%! subplot (2, 1, 1); 71%! rgbplot (cmap, "composite"); 72%! subplot (2, 1, 2); 73%! rgbplot (cmap); 74