Mercurial > hg > octave-image
annotate rainbow.m @ 59:8ae91f3e55a5 Octave-Forge-2004.02.12
Add some of the missing functions to the categorical index
author | pkienzle |
---|---|
date | Thu, 12 Feb 2004 07:49:40 +0000 |
parents | 2adef77b98d0 |
children |
rev | line source |
---|---|
0 | 1 ## Copyright (C) 1999,2000 Kai Habel |
2 ## | |
3 ## This program is free software; you can redistribute it and/or modify | |
4 ## it under the terms of the GNU General Public License as published by | |
5 ## the Free Software Foundation; either version 2 of the License, or | |
6 ## (at your option) any later version. | |
7 ## | |
8 ## This program is distributed in the hope that it will be useful, | |
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ## GNU General Public License for more details. | |
12 ## | |
13 ## You should have received a copy of the GNU General Public License | |
14 ## along with this program; if not, write to the Free Software | |
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | |
17 ## -*- texinfo -*- | |
18 ## @deftypefn {Function File} {} rainbow (@var{n}) | |
19 ## Create color colormap. | |
20 ## (red through orange, yellow, green, blue to violet) | |
21 ## The argument @var{n} should be a scalar. If it | |
22 ## is omitted, the length of the current colormap or 64 is assumed. | |
23 ## @end deftypefn | |
24 ## @seealso{colormap} | |
25 | |
26 ## Author: Kai Habel <kai.habel@gmx.de> | |
27 | |
28 function map = rainbow (number) | |
29 ## this colormap is not part of matlab, it is like the prism | |
30 ## colormap map but with a continuous map | |
31 | |
32 if (nargin == 0) | |
40
2adef77b98d0
Remove reference to global variable __current_colormap__; we need to do
pkienzle
parents:
0
diff
changeset
|
33 number = rows (colormap); |
0 | 34 elseif (nargin == 1) |
35 if (! is_scalar (number)) | |
36 error ("rainbow: argument must be a scalar"); | |
37 endif | |
38 else | |
39 usage ("rainbow (number)"); | |
40 endif | |
41 | |
42 if (number == 1) | |
43 map = [1, 0, 0]; | |
44 elseif (number > 1) | |
45 x = linspace (0, 1, number)'; | |
46 r = (x < 2/5) + (x >= 2/5 & x < 3/5) .* (-5 * x + 3)\ | |
47 + (x >= 4/5) .* (10/3 * x - 8/3); | |
48 g = (x < 2/5) .* (5/2 * x) + (x >= 2/5 & x < 3/5)\ | |
49 + (x >= 3/5 & x < 4/5) .* (-5 * x + 4); | |
50 b = (x >= 3/5 & x < 4/5) .* (5 * x - 3) + (x >= 4/5); | |
51 map = [r, g, b]; | |
52 else | |
53 map = []; | |
54 endif | |
55 | |
56 endfunction |