Mercurial > octave-nkf
annotate scripts/image/rainbow.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | 1bf0ce0930be |
children | 2b0cc0b6db61 |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 1999, 2000, 2007, 2009 Kai Habel |
6788 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6788 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6788 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} rainbow (@var{n}) | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
21 ## Create color colormap. This colormap is red through orange, yellow, green, |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
22 ## blue to violet. The argument @var{n} should be a scalar. If it |
6788 | 23 ## is omitted, the length of the current colormap or 64 is assumed. |
24 ## @seealso{colormap} | |
25 ## @end deftypefn | |
26 | |
27 ## Author: Kai Habel <kai.habel@gmx.de> | |
28 | |
29 function map = rainbow (number) | |
30 ## this colormap is not part of matlab, it is like the prism | |
31 ## colormap map but with a continuous map | |
32 | |
33 if (nargin == 0) | |
34 number = rows (colormap); | |
35 elseif (nargin == 1) | |
6791 | 36 if (! isscalar (number)) |
6788 | 37 error ("rainbow: argument must be a scalar"); |
38 endif | |
39 else | |
40 print_usage (); | |
41 endif | |
42 | |
43 if (number == 1) | |
44 map = [1, 0, 0]; | |
45 elseif (number > 1) | |
46 x = linspace (0, 1, number)'; | |
47 r = (x < 2/5) + (x >= 2/5 & x < 3/5) .* (-5 * x + 3)\ | |
48 + (x >= 4/5) .* (10/3 * x - 8/3); | |
49 g = (x < 2/5) .* (5/2 * x) + (x >= 2/5 & x < 3/5)\ | |
50 + (x >= 3/5 & x < 4/5) .* (-5 * x + 4); | |
51 b = (x >= 3/5 & x < 4/5) .* (5 * x - 3) + (x >= 4/5); | |
52 map = [r, g, b]; | |
53 else | |
54 map = []; | |
55 endif | |
56 | |
57 endfunction |