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} =} summer ()
28## @deftypefnx {} {@var{map} =} summer (@var{n})
29## Create color colormap.  This colormap varies from green to yellow.
30##
31## The argument @var{n} must be a scalar.
32## If unspecified, the length of the current colormap, or 64, is used.
33## @seealso{colormap}
34## @end deftypefn
35
36function map = summer (n)
37
38  if (nargin > 1)
39    print_usage ();
40  elseif (nargin == 1)
41    if (! isscalar (n))
42      error ("summer: N must be a scalar");
43    endif
44    n = double (n);
45  else
46    hf = get (0, "currentfigure");
47    if (! isempty (hf))
48      n = rows (get (hf, "colormap"));
49    else
50      n = 64;
51    endif
52  endif
53
54  if (n == 1)
55    map = [0, 0.5, 0.4];
56  elseif (n > 1)
57    r = [0:(n-1)]' / (n - 1);
58    g = 0.5 + r / 2;
59    b = 0.4 * ones (n, 1);
60    map = [r, g, b];
61  else
62    map = zeros (0, 3);
63  endif
64
65endfunction
66
67
68%!demo
69%! ## Show the 'summer' colormap profile and as an image
70%! cmap = summer (256);
71%! subplot (2, 1, 1);
72%!  rgbplot (cmap, "composite");
73%! subplot (2, 1, 2);
74%!  rgbplot (cmap);
75