]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/fill.m
update packages
[CreaPhase.git] / octave_packages / m / plot / fill.m
1 ## Copyright (C) 2007-2012 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.
26 ##
27 ## The optional return value @var{h} is an array of graphics handles to
28 ## the created patch objects.
29 ## @seealso{patch}
30 ## @end deftypefn
31
32 function retval = fill (varargin)
33
34   [h, varargin] = __plt_get_axis_arg__ ("fill", varargin{:});
35
36   htmp = [];
37   iargs = __find_patches__ (varargin{:});
38
39   oldh = gca ();
40   unwind_protect
41     axes (h);
42
43     nextplot = get (h, "nextplot");
44     for i = 1 : length (iargs)
45       if (i > 1 && strncmp (nextplot, "replace", 7))
46         set (h, "nextplot", "add");
47       endif
48       if (i == length (iargs))
49         args = varargin (iargs(i):end);
50       else
51         args = varargin (iargs(i):iargs(i+1)-1);
52       endif
53       newplot ();
54       [tmp, fail] = __patch__ (h, args{:});
55       if (fail)
56         print_usage();
57       endif
58       htmp (end + 1) = tmp;
59     endfor
60     if (strncmp (nextplot, "replace", 7))
61       set (h, "nextplot", nextplot);
62     endif
63   unwind_protect_cleanup
64     axes (oldh);
65   end_unwind_protect
66
67   if (nargout > 0)
68     retval = htmp;
69   endif
70
71 endfunction
72
73 function iargs = __find_patches__ (varargin)
74   iargs = [];
75   i = 1;
76   while (i < nargin)
77     iargs (end + 1) = i;
78     if (ischar (varargin{i})
79         && (strcmpi (varargin{i}, "faces")
80             || strcmpi (varargin{i}, "vertices")))
81       i += 4;
82     elseif (isnumeric (varargin{i}))
83       i += 2;
84     endif
85
86     if (i <= nargin)
87       while (true);
88         if (ischar (varargin{i})
89             && (strcmpi (varargin{i}, "faces")
90                 || strcmpi (varargin{i}, "vertices")))
91           break;
92         elseif (isnumeric (varargin{i}))
93           ## Assume its the colorspec
94           i++;
95           break;
96         elseif (ischar (varargin{i}))
97           colspec = tolower (varargin{i});
98           collen = length (colspec);
99
100           if (strncmp (colspec, "blue", collen)
101               || strncmp (colspec, "black", collen)
102               || strncmp (colspec, "k", collen)
103               || strncmp (colspec, "black", collen)
104               || strncmp (colspec, "red", collen)
105               || strncmp (colspec, "green", collen)
106               || strncmp (colspec, "yellow", collen)
107               || strncmp (colspec, "magenta", collen)
108               || strncmp (colspec, "cyan", collen)
109               || strncmp (colspec, "white", collen))
110             i++;
111             break;
112           endif
113         else
114           i += 2;
115         endif
116       endwhile
117     endif
118   endwhile
119 endfunction
120
121
122 %!demo
123 %! clf
124 %! t1 = (1/16:1/8:1)*2*pi;
125 %! t2 = ((1/16:1/8:1) + 1/32)*2*pi;
126 %! x1 = sin (t1) - 0.8;
127 %! y1 = cos (t1);
128 %! x2 = sin (t2) + 0.8;
129 %! y2 = cos (t2);
130 %! h = fill (x1,y1,'r', x2,y2,'g');
131