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