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} =} ocean () 28## @deftypefnx {} {@var{map} =} ocean (@var{n}) 29## Create color colormap. This colormap varies from black to white with shades 30## of blue. 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 = ocean (n) 38 39 if (nargin > 1) 40 print_usage (); 41 elseif (nargin == 1) 42 if (! isscalar (n)) 43 error ("ocean: 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 cutin = fix (n/3); 59 60 dr = (n - 1) / cutin; 61 r = prepad ([0:dr:(n-1)], n)'; 62 63 dg = (n - 1) / (2 * cutin); 64 g = prepad ([0:dg:(n-1)], n)'; 65 66 b = [0:(n-1)]'; 67 68 map = [r, g, b] / (n - 1); 69 else 70 map = zeros (0, 3); 71 endif 72 73endfunction 74 75 76%!demo 77%! ## Show the 'ocean' colormap profile and as an image 78%! cmap = ocean (256); 79%! subplot (2, 1, 1); 80%! rgbplot (cmap, "composite"); 81%! subplot (2, 1, 2); 82%! rgbplot (cmap); 83