1########################################################################
2##
3## Copyright (C) 2012-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} =} lines ()
28## @deftypefnx {} {@var{map} =} lines (@var{n})
29## Create color colormap.  This colormap is composed of the list of colors
30## in the current axes @qcode{"ColorOrder"} property.  The default is blue,
31## orange, yellow, purple, green, light blue, and dark red.
32##
33## The argument @var{n} must be a scalar.
34## If unspecified, the length of the current colormap, or 64, is used.
35## @seealso{colormap}
36## @end deftypefn
37
38function map = lines (n)
39
40  hf = get (groot, "currentfigure");
41  if (nargin > 1)
42    print_usage ();
43  elseif (nargin == 1)
44    if (! isscalar (n))
45      error ("lines: N must be a scalar");
46    endif
47    n = double (n);
48  else
49    if (! isempty (hf))
50      n = rows (get (hf, "colormap"));
51    else
52      n = 64;
53    endif
54  endif
55
56  if (n == 1)
57    map = [0, 0, 1];
58  elseif (n > 1)
59    hax = get (hf, "currentaxes");
60    if (! isempty (hax))
61      C = get (hax, "colororder");
62    else
63      C = get (groot, "defaultaxescolororder");
64    endif
65    nr = rows (C);
66    map = C(rem (0:(n-1), nr) + 1, :);
67  else
68    map = zeros (0, 3);
69  endif
70
71endfunction
72
73
74%!demo
75%! ## Show the 'lines' colormap profile and as an image
76%! cmap = lines (21); # default has 7 colors, therefore cycle 3 times
77%! subplot (2, 1, 1);
78%!  rgbplot (cmap, "composite");
79%! subplot (2, 1, 2);
80%!  rgbplot (cmap);
81