7020
|
1 ## Copyright (C) 2007 David Bateman |
|
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} {} fill (@var{x}, @var{y}, @var{c}) |
|
21 ## @deftypefnx {Function File} {} fill (@var{x1}, @var{y1}, @var{c1}, @var{x2}, @var{y2}, @var{c2}) |
|
22 ## @deftypefnx {Function File} {} fill (@dots{}, @var{prop}, @var{val}) |
|
23 ## @deftypefnx {Function File} {} fill (@var{h}, @dots{}) |
|
24 ## @deftypefnx {Function File} {@var{h} = } fill (@dots{}) |
|
25 ## Create one or more filled patch objects, returning a patch object for each. |
|
26 ## @end deftypefn |
|
27 |
|
28 function h = fill (varargin) |
|
29 |
|
30 htmp = []; |
|
31 |
|
32 if (isscalar (varargin{1}) && ishandle (varargin{1})) |
|
33 h = varargin {1}; |
|
34 if (! strcmp (get (h, "type"), "axes")) |
|
35 error ("fill: expecting first argument to be an axes object"); |
|
36 endif |
|
37 |
|
38 iargs = __find_patches__ (varargin{:}) + 1; |
|
39 oldh = gca (); |
|
40 unwind_protect |
|
41 axes (h); |
|
42 |
|
43 for i = 1 : length (iargs) |
|
44 if (i == length (iargs)) |
|
45 args = varargin (iargs(i):end); |
|
46 else |
|
47 args = varargin (iargs(i):iargs(i+1)-1); |
|
48 endif |
7041
|
49 newplot (); |
7020
|
50 [tmp, fail] = __patch__ (h, args{:}); |
|
51 if (fail) |
|
52 print_usage(); |
|
53 endif |
|
54 htmp (end + 1) = tmp; |
|
55 endfor |
|
56 unwind_protect_cleanup |
|
57 axes (oldh); |
|
58 end_unwind_protect |
|
59 else |
|
60 iargs = __find_patches__ (varargin{:}); |
|
61 for i = 1 : length (iargs) |
|
62 if (i == length (iargs)) |
|
63 args = varargin (iargs(i):end); |
|
64 else |
|
65 args = varargin (iargs(i):iargs(i+1)-1); |
|
66 endif |
7041
|
67 newplot (); |
7020
|
68 [tmp, fail] = __patch__ (gca (), args{:}); |
|
69 if (fail) |
|
70 print_usage(); |
|
71 endif |
|
72 htmp (end + 1) = tmp; |
|
73 endfor |
|
74 endif |
|
75 if (nargout > 0) |
|
76 h = htmp; |
|
77 endif |
|
78 endfunction |
|
79 |
|
80 function iargs = __find_patches__ (varargin) |
|
81 iargs = []; |
|
82 i = 1; |
|
83 while (i < nargin) |
|
84 iargs (end + 1) = i; |
|
85 if (ischar (varargin {i}) && (strcmp (tolower (varargin{i}), "faces") || |
|
86 strcmp (tolower (varargin{i}), "vertices"))) |
|
87 i += 4; |
|
88 elseif (isnumeric (varargin {i})) |
|
89 i += 2; |
|
90 endif |
|
91 |
|
92 if (i <= nargin) |
|
93 while (true); |
|
94 if (ischar (varargin {i}) && |
|
95 (strcmp (tolower (varargin{i}), "faces") || |
|
96 strcmp (tolower (varargin{i}), "vertices"))) |
|
97 break; |
|
98 elseif (isnumeric (varargin {i})) |
|
99 ## Assume its the colorspec |
|
100 i++; |
|
101 break; |
|
102 elseif (ischar (varargin {i})) |
|
103 colspec = tolower (varargin {i}); |
|
104 collen = length (colspec); |
|
105 |
|
106 if (strncmp (colspec, "blue", collen) || |
|
107 strncmp (colspec, "black", collen) || |
|
108 strncmp (colspec, "k", collen) || |
|
109 strncmp (colspec, "black", collen) || |
|
110 strncmp (colspec, "red", collen) || |
|
111 strncmp (colspec, "green", collen) || |
|
112 strncmp (colspec, "yellow", collen) || |
|
113 strncmp (colspec, "magenta", collen) || |
|
114 strncmp (colspec, "cyan", collen) || |
|
115 strncmp (colspec, "white", collen)) |
|
116 i++; |
|
117 break; |
|
118 endif |
|
119 else |
|
120 i += 2; |
|
121 endif |
|
122 endwhile |
|
123 endif |
|
124 endwhile |
|
125 endfunction |
|
126 |
|
127 %!demo |
|
128 %! close all; |
|
129 %! t1 = (1/16:1/8:1)'*2*pi; |
|
130 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi; |
|
131 %! x1 = sin(t1) - 0.8; |
|
132 %! y1 = cos(t1); |
|
133 %! x2 = sin(t2) + 0.8; |
|
134 %! y2 = cos(t2); |
|
135 %! h = fill(x1,y1,'r',x2,y2,'g') |