Mercurial > octave-nkf
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 | 4 files changed, 73 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/module.mk Tue Jan 24 09:51:48 2012 -0800 +++ b/scripts/image/module.mk Tue Jan 24 17:12:09 2012 -0800 @@ -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 \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/image/spinmap.m Tue Jan 24 17:12:09 2012 -0800 @@ -0,0 +1,72 @@ +## Copyright (C) 2007-2012 Kai Habel +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @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. +## +## 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 = 5, 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 = cmap_orig = get (gcf (), "colormap"); + + t0 = clock; + while (etime (clock, t0) < t) + cmap = shift (cmap, inc, 1); + set (gcf (), "colormap", cmap); + drawnow (); + endwhile + + 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); +
--- a/scripts/plot/module.mk Tue Jan 24 09:51:48 2012 -0800 +++ b/scripts/plot/module.mk Tue Jan 24 17:12:09 2012 -0800 @@ -166,7 +166,6 @@ plot/sombrero.m \ plot/specular.m \ plot/sphere.m \ - plot/spinmap.m \ plot/stairs.m \ plot/stem.m \ plot/stem3.m \
--- a/scripts/plot/spinmap.m Tue Jan 24 09:51:48 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -## Copyright (C) 2007-2012 Kai Habel -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <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. -## -## A higher value of @var{inc} causes a faster cycle through the -## colormap. -## @seealso{gca, colorbar} -## @end deftypefn - -## Author: Kai Habel <kai.habel at gmx.de> - -function spinmap (t, inc) - - if (nargin == 0) - inc = 2; - t = 5; - elseif (nargin == 1) - inc = 2; - endif - - cmap = get (gcf (), "colormap"); - clen = rows (cmap); - - t0 = clock; - - while (etime (clock, t0) < t) - for n = 1:inc:clen - newmap = shift (cmap, n, 1); - set (gcf (), "colormap", newmap); - drawnow (); - endfor - endwhile - - set (gcf (), "colormap", cmap); - -endfunction -