Mercurial > octave
annotate scripts/image/ocean.m @ 33617:ec2635a02328 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 21 May 2024 18:29:03 +0200 |
parents | d8e5e55c3cf5 |
children |
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 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 1994-2024 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/>. |
2313 | 7 ## |
8 ## This file is part of Octave. | |
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 |
2313 | 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. |
2313 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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. |
2313 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 ######################################################################## |
559 | 25 |
3381 | 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} =} ocean () |
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} =} ocean (@var{n}) |
11420
466ba499eff5
Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents:
9751
diff
changeset
|
29 ## Create color colormap. This colormap varies from black to white with shades |
466ba499eff5
Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents:
9751
diff
changeset
|
30 ## of blue. |
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. |
32647
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
33 ## If @var{n} is not specified the length of the current colormap is used. If |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
34 ## there is no current colormap the default value of 256 is used. |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
35 ## @seealso{colormap} |
3373 | 36 ## @end deftypefn |
1024 | 37 |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
38 function map = ocean (n) |
1024 | 39 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
40 if (nargin == 1) |
32737
d8e5e55c3cf5
Tighten input validation for all colormaps (bug #65011).
Rik <rik@octave.org>
parents:
32653
diff
changeset
|
41 if (! (isscalar (n) && isreal (n) && n == fix (n))) |
d8e5e55c3cf5
Tighten input validation for all colormaps (bug #65011).
Rik <rik@octave.org>
parents:
32653
diff
changeset
|
42 error ("ocean: N must be a scalar integer"); |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
43 endif |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
44 n = double (n); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
45 else |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
46 hf = get (0, "currentfigure"); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
47 if (! isempty (hf)) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
48 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
|
49 else |
32647
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
50 n = 256; |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
51 endif |
559 | 52 endif |
53 | |
14641
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
54 if (n == 1) |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
55 map = [0, 0, 0]; |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
56 elseif (n > 1) |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
57 cutin = fix (n/3); |
2325 | 58 |
14641
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
59 dr = (n - 1) / cutin; |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
60 r = prepad ([0:dr:(n-1)], n)'; |
1024 | 61 |
14641
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
62 dg = (n - 1) / (2 * cutin); |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
63 g = prepad ([0:dg:(n-1)], n)'; |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
64 |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
65 b = [0:(n-1)]'; |
1024 | 66 |
14641
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
67 map = [r, g, b] / (n - 1); |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
68 else |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
69 map = zeros (0, 3); |
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
70 endif |
559 | 71 |
72 endfunction | |
9751
2b0cc0b6db61
Add demos for colormap functions
Soren Hauberg <hauberg@gmail.com>
parents:
7017
diff
changeset
|
73 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
74 |
9751
2b0cc0b6db61
Add demos for colormap functions
Soren Hauberg <hauberg@gmail.com>
parents:
7017
diff
changeset
|
75 %!demo |
20724
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20158
diff
changeset
|
76 %! ## Show the 'ocean' 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
|
77 %! cmap = ocean (256); |
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20158
diff
changeset
|
78 %! subplot (2, 1, 1); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21973
diff
changeset
|
79 %! 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
|
80 %! subplot (2, 1, 2); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21973
diff
changeset
|
81 %! rgbplot (cmap); |
32647
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
82 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
83 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
84 %!assert (size (ocean ()), [256, 3]) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
85 %!assert (size (ocean (16)), [16, 3]) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
86 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
87 %!assert (ocean (1), [0, 0, 0]) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
88 %!assert (ocean (true), double ([0, 0, 0])) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
89 %!assert (ocean (char (1)), double ([0, 0, 0])) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
90 %!assert (ocean (int32 (1)), double ([0, 0, 0])) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
91 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
92 %!assert (ocean (0), zeros (0, 3)) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
93 %!assert (ocean (-1), zeros (0, 3)) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
94 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
95 %!assert (ocean()(1,:), [0, 0, 0]) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
96 %!assert (ocean()(end,:), [1, 1, 1]) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
97 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
98 %!test |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
99 %! a = zeros (11, 3); |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
100 %! a([9:11],1) = [1/3, 2/3, 1]; |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
101 %! a([6:11], 2) = 1/6:1/6:1; |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
102 %! a(:, 3) = 0:.1:1; |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
103 %! assert (ocean (11), a, eps) |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
104 |
dfb9b770ae77
Increase default colormap size to 256 colors, add colormap BISTs (bug #65010)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
32632
diff
changeset
|
105 ## Input validation |
32737
d8e5e55c3cf5
Tighten input validation for all colormaps (bug #65011).
Rik <rik@octave.org>
parents:
32653
diff
changeset
|
106 %!error <N must be a scalar integer> ocean ("foo") |
d8e5e55c3cf5
Tighten input validation for all colormaps (bug #65011).
Rik <rik@octave.org>
parents:
32653
diff
changeset
|
107 %!error <N must be a scalar integer> ocean ([1, 2, 3]) |
d8e5e55c3cf5
Tighten input validation for all colormaps (bug #65011).
Rik <rik@octave.org>
parents:
32653
diff
changeset
|
108 %!error <N must be a scalar integer> ocean ({1, 2, 3}) |