Mercurial > hg > octave-lojdl
changeset 14264:284656167c25
spinmap.m: Revamp function and make Matlab-compatible.
* spinmap.m: Add 'inf' option. Add ability to have negative increments.
Add demo block. Update docstring.
* image/module.mk, plot/module.mk: Move spinmap to image/ directory to
be with other colormap functions.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 24 Jan 2012 17:12:09 -0800 |
parents | 1f911333ed3d |
children | 37ca58f9a887 |
files | scripts/image/module.mk scripts/image/spinmap.m scripts/plot/module.mk scripts/plot/spinmap.m |
diffstat | 3 files changed, 38 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/module.mk +++ b/scripts/image/module.mk @@ -32,6 +32,7 @@ image/rgb2hsv.m \ image/rgb2ind.m \ image/rgb2ntsc.m \ + image/spinmap.m \ image/spring.m \ image/summer.m \ image/white.m \
rename from scripts/plot/spinmap.m rename to scripts/image/spinmap.m --- a/scripts/plot/spinmap.m +++ b/scripts/image/spinmap.m @@ -17,41 +17,56 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} spinmap (@var{t}, @var{inc}) -## Cycle the colormap for @var{t} seconds with an increment -## of @var{inc}. Both parameters are optional. The default cycle time -## is 5 seconds and the default increment is 2. +## @deftypefn {Function File} {} spinmap () +## @deftypefnx {Function File} {} spinmap (@var{t}) +## @deftypefnx {Function File} {} spinmap (@var{t}, @var{inc}) +## @deftypefnx {Function File} {} spinmap ("inf") +## Cycle the colormap for @var{t} seconds with a color increment of @var{inc}. +## Both parameters are optional. The default cycle time is 5 seconds and the +## default increment is 2. If the option "inf" is given then cycle +## continuously until @kbd{Control-C} is pressed. ## -## A higher value of @var{inc} causes a faster cycle through the -## colormap. -## @seealso{gca, colorbar} +## When rotating the original color 1 becomes color 2, color 2 becomes +## color 3, etc. A positive or negative increment is allowed and a higher +## value of @var{inc} will cause faster cycling through the colormap. +## @seealso{colormap} ## @end deftypefn ## Author: Kai Habel <kai.habel at gmx.de> -function spinmap (t, inc) +function spinmap (t = 5, inc = 2) - if (nargin == 0) - inc = 2; - t = 5; - elseif (nargin == 1) - inc = 2; + if (nargin > 2) + print_usage (); + elseif (ischar (t)) + if (strcmpi (t, "inf")) + t = Inf; + else + error ('spinmap: time T must be a real scalar or "inf"'); + endif + elseif (! isscalar (t) || ! isreal (t)) + error ("spinmap: time T must be a real scalar"); endif - cmap = get (gcf (), "colormap"); - clen = rows (cmap); + cmap = cmap_orig = get (gcf (), "colormap"); t0 = clock; - while (etime (clock, t0) < t) - for n = 1:inc:clen - newmap = shift (cmap, n, 1); - set (gcf (), "colormap", newmap); - drawnow (); - endfor + cmap = shift (cmap, inc, 1); + set (gcf (), "colormap", cmap); + drawnow (); endwhile - set (gcf (), "colormap", cmap); + set (gcf (), "colormap", cmap_orig); endfunction + +%!demo +%! clf; +%! colormap (rainbow (128)); +%! imagesc (1:8); +%! axis off; +%! title ("Rotate color bars to the right"); +%! spinmap (3, 1); +