annotate scripts/image/spinmap.m @ 17692:38cf56b77274

Overhaul image, imagesc to use newplot and support low-level invocation form. * scripts/image/image.m: New variable do_new indicates high-level calling form. For high-level invocation, call newplot before __img__. Correct linearity check if vectors are reversed (high-to-low values). Only apply image properties to axes if doing a high-level invocation. * scripts/image/imagesc.m: New variable do_new indicates high-level calling form. Delete subfunction __imagesc__ and incorporate minimal amount of code into imagesc. Only apply climits for high-level invocation.
author Rik <rik@octave.org>
date Fri, 18 Oct 2013 16:27:44 -0700
parents bc924baa2c4e
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11589
diff changeset
1 ## Copyright (C) 2007-2012 Kai Habel
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
2 ##
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
3 ## This file is part of Octave.
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
4 ##
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
8 ## your option) any later version.
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
9 ##
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
14 ##
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
17 ## <http://www.gnu.org/licenses/>.
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
18
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
20 ## @deftypefn {Function File} {} spinmap ()
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefnx {Function File} {} spinmap (@var{t})
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
22 ## @deftypefnx {Function File} {} spinmap (@var{t}, @var{inc})
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## @deftypefnx {Function File} {} spinmap ("inf")
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
24 ## Cycle the colormap for @var{t} seconds with a color increment of @var{inc}.
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
25 ## Both parameters are optional. The default cycle time is 5 seconds and the
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 14264
diff changeset
26 ## default increment is 2. If the option @qcode{"inf"} is given then cycle
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
27 ## continuously until @kbd{Control-C} is pressed.
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
28 ##
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
29 ## When rotating the original color 1 becomes color 2, color 2 becomes
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
30 ## color 3, etc. A positive or negative increment is allowed and a higher
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
31 ## value of @var{inc} will cause faster cycling through the colormap.
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
32 ## @seealso{colormap}
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
33 ## @end deftypefn
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
34
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
35 ## Author: Kai Habel <kai.habel at gmx.de>
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
36
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
37 function spinmap (t = 5, inc = 2)
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
38
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
39 if (nargin > 2)
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
40 print_usage ();
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
41 elseif (ischar (t))
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
42 if (strcmpi (t, "inf"))
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
43 t = Inf;
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
44 else
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
45 error ('spinmap: time T must be a real scalar or "inf"');
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
46 endif
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
47 elseif (! isscalar (t) || ! isreal (t))
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
48 error ("spinmap: time T must be a real scalar");
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
49 endif
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
50
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
51 cmap = cmap_orig = get (gcf (), "colormap");
7163
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
52
d4d8c7b33e16 [project @ 2007-11-12 21:54:07 by jwe]
jwe
parents:
diff changeset
53 t0 = clock;
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
54 while (etime (clock, t0) < t)
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55 cmap = shift (cmap, inc, 1);
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 set (gcf (), "colormap", cmap);
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 drawnow ();
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
58 endwhile
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
59
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 set (gcf (), "colormap", cmap_orig);
7164
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
61
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
62 endfunction
2b5e6c0a9df9 [project @ 2007-11-12 22:04:42 by jwe]
jwe
parents: 7163
diff changeset
63
14264
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
64
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65 %!demo
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 %! clf;
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
67 %! colormap (rainbow (128));
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
68 %! imagesc (1:8);
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %! axis off;
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 %! title ("Rotate color bars to the right");
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
71 %! spinmap (3, 1);
284656167c25 spinmap.m: Revamp function and make Matlab-compatible.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72