annotate scripts/image/rainbow.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 1999-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
7 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
14 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
19 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6791
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
25
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20724
diff changeset
27 ## @deftypefn {} {@var{map} =} rainbow ()
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20724
diff changeset
28 ## @deftypefnx {} {@var{map} =} rainbow (@var{n})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
29 ## Create color colormap. This colormap ranges from red through orange,
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
30 ## yellow, green, blue, to violet.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
32 ## The argument @var{n} must be a scalar.
11420
466ba499eff5 Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents: 9751
diff changeset
33 ## If unspecified, the length of the current colormap, or 64, is used.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
34 ## @seealso{colormap}
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
35 ## @end deftypefn
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
36
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
37 ## this colormap is not part of matlab, it is like the prism
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
38 ## colormap map but with a continuous map
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
39
24800
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
40 function map = rainbow (n)
11420
466ba499eff5 Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents: 9751
diff changeset
41
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27978
diff changeset
42 if (nargin == 1)
24800
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
43 if (! isscalar (n))
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
44 error ("rainbow: N must be a scalar");
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
45 endif
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
46 n = double (n);
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
47 else
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
48 hf = get (0, "currentfigure");
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
49 if (! isempty (hf))
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
50 n = rows (get (hf, "colormap"));
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
51 else
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
52 n = 64;
2dc04b6e1740 Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents: 24534
diff changeset
53 endif
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
54 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
55
11420
466ba499eff5 Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents: 9751
diff changeset
56 if (n == 1)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
57 map = [1, 0, 0];
11420
466ba499eff5 Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents: 9751
diff changeset
58 elseif (n > 1)
16466
ac332eb727dd Simplify calculation of colormaps
Rik <rik@octave.org>
parents: 15720
diff changeset
59 x = [0:(n-1)]' / (n - 1);
14369
932ba2bb9060 rainbow.m: Reformat and fix typo (bug #35549)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14279
diff changeset
60
16466
ac332eb727dd Simplify calculation of colormaps
Rik <rik@octave.org>
parents: 15720
diff changeset
61 r = ( (x < 2/5)
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14369
diff changeset
62 + (x >= 2/5 & x < 3/5) .* (-5 * x + 3)
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14369
diff changeset
63 + (x >= 4/5) .* (10/3 * x - 8/3));
14369
932ba2bb9060 rainbow.m: Reformat and fix typo (bug #35549)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14279
diff changeset
64
16466
ac332eb727dd Simplify calculation of colormaps
Rik <rik@octave.org>
parents: 15720
diff changeset
65 g = ( (x < 2/5) .* (5/2 * x)
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14369
diff changeset
66 + (x >= 2/5 & x < 3/5)
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14369
diff changeset
67 + (x >= 3/5 & x < 4/5) .* (-5 * x + 4));
14369
932ba2bb9060 rainbow.m: Reformat and fix typo (bug #35549)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14279
diff changeset
68
16466
ac332eb727dd Simplify calculation of colormaps
Rik <rik@octave.org>
parents: 15720
diff changeset
69 b = ( (x >= 3/5 & x < 4/5) .* (5 * x - 3)
ac332eb727dd Simplify calculation of colormaps
Rik <rik@octave.org>
parents: 15720
diff changeset
70 + (x >= 4/5));
14369
932ba2bb9060 rainbow.m: Reformat and fix typo (bug #35549)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14279
diff changeset
71
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
72 map = [r, g, b];
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
73 else
14641
5f1d4def40e1 improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents: 14640
diff changeset
74 map = zeros (0, 3);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
75 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
76
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
77 endfunction
9751
2b0cc0b6db61 Add demos for colormap functions
Soren Hauberg <hauberg@gmail.com>
parents: 9245
diff changeset
78
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
79
9751
2b0cc0b6db61 Add demos for colormap functions
Soren Hauberg <hauberg@gmail.com>
parents: 9245
diff changeset
80 %!demo
20724
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20158
diff changeset
81 %! ## Show the 'rainbow' colormap profile and as an image
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20158
diff changeset
82 %! cmap = rainbow (256);
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20158
diff changeset
83 %! subplot (2, 1, 1);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21973
diff changeset
84 %! rgbplot (cmap, "composite");
20724
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20158
diff changeset
85 %! subplot (2, 1, 2);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21973
diff changeset
86 %! rgbplot (cmap);