7017
|
1 ## Copyright (C) 2005, 2007 John W. Eaton |
6807
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6807
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6807
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} patch () |
|
21 ## @deftypefnx {Function File} {} patch (@var{x}, @var{y}, @var{c}) |
|
22 ## @deftypefnx {Function File} {} patch (@var{x}, @var{y}, @var{c}, @var{opts}) |
7020
|
23 ## @deftypefnx {Function File} {} patch ('Faces', @var{f}, 'Vertices', @var{v}, @dots{}) |
|
24 ## @deftypefnx {Function File} {} patch (@dots{}, @var{prop}, @var{val}) |
6988
|
25 ## @deftypefnx {Function File} {} patch (@var{h}, @dots{}) |
7020
|
26 ## @deftypefnx {Function File} {@var{h} = } patch (@dots{}) |
6895
|
27 ## Create patch object from @var{x} and @var{y} with color @var{c} and |
|
28 ## insert in the current axes object. Return handle to patch object. |
|
29 ## |
|
30 ## For a uniform colored patch, @var{c} can be given as an RGB vector, |
|
31 ## scalar value referring to the current colormap, or string value (for |
|
32 ## example, "r" or "red"). |
6807
|
33 ## @end deftypefn |
|
34 |
|
35 ## Author: jwe |
|
36 |
|
37 function h = patch (varargin) |
|
38 |
7215
|
39 [h, varargin] = __plt_get_axis_arg__ ("patch", varargin{:}); |
|
40 oldh = gca (); |
|
41 if (isnan(h)) |
|
42 h = oldh; |
7020
|
43 endif |
7215
|
44 unwind_protect |
|
45 axes (h); |
|
46 [tmp, fail] = __patch__ (h, varargin{:}); |
|
47 unwind_protect_cleanup |
|
48 axes (oldh); |
|
49 end_unwind_protect |
7020
|
50 |
|
51 if (fail) |
|
52 print_usage (); |
6988
|
53 endif |
6807
|
54 |
|
55 if (nargout > 0) |
|
56 h = tmp; |
|
57 endif |
|
58 |
|
59 endfunction |
7020
|
60 |
|
61 %!demo |
|
62 %! ## Patches with same number of vertices |
|
63 %! close all; |
|
64 %! t1 = (1/16:1/8:1)'*2*pi; |
|
65 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi; |
|
66 %! x1 = sin(t1) - 0.8; |
|
67 %! y1 = cos(t1); |
|
68 %! x2 = sin(t2) + 0.8; |
|
69 %! y2 = cos(t2); |
|
70 %! patch([x1,x2],[y1,y2],'r'); |
|
71 |
|
72 %!demo |
|
73 %! ## Unclosed patch |
|
74 %! close all; |
|
75 %! t1 = (1/16:1/8:1)'*2*pi; |
|
76 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi; |
|
77 %! x1 = sin(t1) - 0.8; |
|
78 %! y1 = cos(t1); |
|
79 %! x2 = sin(t2) + 0.8; |
|
80 %! y2 = cos(t2); |
|
81 %! patch([[x1;NaN(8,1)],x2],[[y1;NaN(8,1)],y2],'r'); |
|
82 |
|
83 %!demo |
|
84 %! ## Specify vertices and faces separately |
|
85 %! close all; |
|
86 %! t1 = (1/16:1/8:1)'*2*pi; |
|
87 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi; |
|
88 %! x1 = sin(t1) - 0.8; |
|
89 %! y1 = cos(t1); |
|
90 %! x2 = sin(t2) + 0.8; |
|
91 %! y2 = cos(t2); |
|
92 %! vert = [x1, y1; x2, y2]; |
|
93 %! fac = [1:8,NaN(1,8);9:24]; |
|
94 %! patch('Faces',fac,'Vertices',vert,'FaceColor','r'); |
|
95 |
|
96 %!demo |
|
97 %! ## Property change on multiple patches |
|
98 %! close all; |
|
99 %! t1 = (1/16:1/8:1)'*2*pi; |
|
100 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi; |
|
101 %! x1 = sin(t1) - 0.8; |
|
102 %! y1 = cos(t1); |
|
103 %! x2 = sin(t2) + 0.8; |
|
104 %! y2 = cos(t2); |
|
105 %! h = patch([x1,x2],[y1,y2],cat (3,[0,0],[1,0],[0,1])); |
|
106 %! pause (1); |
|
107 %! set (h, 'FaceColor', 'r'); |