comparison scripts/plot/shading.m @ 17074:bade805dc0af

shading.m: Update to use new __plt_get_axis_arg__. * scripts/plot/shading.m: Update to use new __plt_get_axis_arg__. Use switch instead of if/else tree. Eliminate unnecessary for loop.
author Rik <rik@octave.org>
date Wed, 24 Jul 2013 23:12:46 -0700
parents 5d3a684236b0
children c2b2c7ddf93c
comparison
equal deleted inserted replaced
17073:55956e8e21c9 17074:bade805dc0af
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} shading (@var{type}) 20 ## @deftypefn {Function File} {} shading (@var{type})
21 ## @deftypefnx {Function File} {} shading (@var{ax}, @dots{}) 21 ## @deftypefnx {Function File} {} shading (@var{ax}, @var{type})
22 ## Set the shading of surface or patch graphic objects. Valid arguments 22 ## Set the shading of surface or patch graphic objects. Valid arguments
23 ## for @var{type} are 23 ## for @var{type} are
24 ## 24 ##
25 ## @table @asis 25 ## @table @asis
26 ## @item "flat" 26 ## @item "flat"
32 ## @item "interp" 32 ## @item "interp"
33 ## Color between patch vertices are interpolated and the patch edges are 33 ## Color between patch vertices are interpolated and the patch edges are
34 ## invisible. 34 ## invisible.
35 ## @end table 35 ## @end table
36 ## 36 ##
37 ## If @var{ax} is given the shading is applied to axis @var{ax} instead 37 ## If @var{hax} is given the shading is applied to axis @var{hax} instead
38 ## of the current axis. 38 ## of the current axis.
39 ## @end deftypefn 39 ## @end deftypefn
40 40
41 ## Author: Kai Habel <kai.habel@gmx.de> 41 ## Author: Kai Habel <kai.habel@gmx.de>
42 42
43 function shading (varargin) 43 function shading (varargin)
44 44
45 [ax, varargin] = __plt_get_axis_arg__ ("shading", varargin{:}); 45 [hax, varargin, nargin] = __plt_get_axis_arg__ ("shading", varargin{:});
46 46
47 if (nargin != 1 && nargin != 2) 47 if (nargin != 1)
48 print_usage (); 48 print_usage ();
49 endif 49 endif
50 50
51 mode = varargin{1}; 51 mode = varargin{1};
52 52
53 h1 = findobj (ax, "type", "patch"); 53 if (isempty (hax))
54 h2 = findobj (ax, "type", "surface"); 54 hax = gca ();
55 endif
55 56
56 obj = [h1(:); h2(:)]; 57 hp = findobj (hax, "type", "patch");
58 hs = findobj (hax, "type", "surface");
59 hall = [hp(:); hs(:)];
57 60
58 for n = 1:numel (obj) 61 switch (lower (mode))
59 h = obj(n); 62 case "flat"
60 if (strcmpi (mode, "flat")) 63 set (hall, "facecolor", "flat");
61 set (h, "facecolor", "flat"); 64 set (hall, "edgecolor", "none");
62 set (h, "edgecolor", "none"); 65 case "interp"
63 elseif (strcmpi (mode, "interp")) 66 set (hall, "facecolor", "interp");
64 set (h, "facecolor", "interp"); 67 set (hall, "edgecolor", "none");
65 set (h, "edgecolor", "none"); 68 case "faceted"
66 elseif (strcmpi (mode, "faceted")) 69 set (hall, "facecolor", "flat");
67 set (h, "facecolor", "flat"); 70 set (hall, "edgecolor", [0 0 0]);
68 set (h, "edgecolor", [0 0 0]); 71 otherwise
69 else 72 error ('shading: Invalid MODE "%s"', mode);
70 error ("shading: unknown argument"); 73 endswitch
71 endif
72 endfor
73 74
74 endfunction 75 endfunction
75 76
76 77
77 %!demo 78 %!demo