]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/shading.m
update packages
[CreaPhase.git] / octave_packages / m / plot / shading.m
1 ## Copyright (C) 2006-2012 Kai Habel
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} shading (@var{type})
21 ## @deftypefnx {Function File} {} shading (@var{ax}, @dots{})
22 ## Set the shading of surface or patch graphic objects.  Valid arguments
23 ## for @var{type} are
24 ##
25 ## @table @asis
26 ## @item "flat"
27 ## Single colored patches with invisible edges.
28 ##
29 ## @item "faceted"
30 ## Single colored patches with visible edges.
31 ##
32 ## @item "interp"
33 ## Color between patch vertices are interpolated and the patch edges are
34 ## invisible.
35 ## @end table
36 ##
37 ## If @var{ax} is given the shading is applied to axis @var{ax} instead
38 ## of the current axis.
39 ## @end deftypefn
40
41 ## Author: Kai Habel <kai.habel@gmx.de>
42
43 function shading (varargin)
44
45   [ax, varargin] = __plt_get_axis_arg__ ("shading", varargin{:});
46
47   if (nargin != 1 && nargin != 2)
48     print_usage ();
49   endif
50
51   mode = varargin{1};
52
53   h1 = findobj (ax, "type", "patch");
54   h2 = findobj (ax, "type", "surface");
55
56   obj = [h1(:); h2(:)];
57
58   for n = 1:numel(obj)
59     h = obj(n);
60     if (strcmpi (mode, "flat"))
61       set (h, "facecolor", "flat");
62       set (h, "edgecolor", "none");
63     elseif (strcmpi (mode, "interp"))
64       set (h, "facecolor", "interp");
65       set (h, "edgecolor", "none");
66     elseif (strcmpi (mode, "faceted"))
67       set (h, "facecolor", "flat");
68       set (h, "edgecolor", [0 0 0]);
69     else
70       error ("shading: unknown argument");
71     endif
72   endfor
73
74 endfunction
75
76
77 %!demo
78 %! clf
79 %! colormap (jet)
80 %! sombrero
81 %! shading faceted
82 %! title ('shading "faceted"')
83
84 %!demo
85 %! clf
86 %! sombrero
87 %! shading flat
88 %! title ('shading "flat"')
89
90 %!demo
91 %! clf
92 %! sombrero
93 %! shading interp
94 %! title ('shading "interp"')
95
96 %!demo
97 %! clf
98 %! pcolor (peaks ())
99 %! shading faceted
100 %! title ('shading "faceted"')
101
102 %!demo
103 %! clf
104 %! pcolor (peaks ())
105 %! shading flat
106 %! title ('shading "flat"')
107
108 %!demo
109 %! clf
110 %! pcolor (peaks ())
111 %! shading interp
112 %! title ('shading "interp"')
113