changelog shortlog tags changeset files revisions annotate raw

scripts/image/colormap.m

changeset 10289: 4b124317dc38
parent:5dd06f19e9be
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (58 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2003, 2005,
2## 2006, 2007, 2009 John W. Eaton
3##
4## This file is part of Octave.
5##
6## Octave is free software; you can redistribute it and/or modify it
7## under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
10##
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
19
20## -*- texinfo -*-
21## @deftypefn {Function File} {} colormap (@var{map})
22## @deftypefnx {Function File} {} colormap ("default")
23## Set the current colormap.
24##
25## @code{colormap (@var{map})} sets the current colormap to @var{map}. The
26## color map should be an @var{n} row by 3 column matrix. The columns
27## contain red, green, and blue intensities respectively. All entries
28## should be between 0 and 1 inclusive. The new colormap is returned.
29##
30## @code{colormap ("default")} restores the default colormap (the
31## @code{jet} map with 64 entries). The default colormap is returned.
32##
33## With no arguments, @code{colormap} returns the current color map.
34## @seealso{jet}
35## @end deftypefn
36
37## Author: Tony Richardson <arichard@stark.cc.oh.us>
38## Created: July 1994
39## Adapted-By: jwe
40
41function cmap = colormap (map)
42
43 if (nargin > 1)
44 print_usage ();
45 endif
46
47 if (nargin == 1)
48
49 if (ischar (map))
50 if (strcmp (map, "default"))
51 map = jet (64);
52 else
53 map = feval (map);
54 endif
55 endif
56
57 if (! isempty (map))
58 if (columns (map) != 3)
59 error ("colormap: map must have 3 columns: [R,G,B]");
60 endif
61 if (min (min (map)) < 0 || max (max (map)) > 1)
62 error ("colormap: map must have values in [0,1]");
63 endif
64 ## Set the new color map
65 set (gcf (), "colormap", map);
66 endif
67
68 endif
69
70 ## Return current color map.
71 if (nargout > 0 || (nargout == 0 && nargin == 0))
72 cmap = get (gcf (), "colormap");
73 endif
74
75endfunction