changelog shortlog tags changeset files revisions annotate raw

scripts/plot/fill.m

changeset 10289: 4b124317dc38
parent:a013ff655ca4
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (35 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2007, 2008, 2009 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
28function retval = fill (varargin)
29
30 [h, varargin] = __plt_get_axis_arg__ ("fill", varargin{:});
31
32 htmp = [];
33 iargs = __find_patches__ (varargin{:});
34
35 oldh = gca ();
36 unwind_protect
37 axes (h);
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
45 newplot ();
46 [tmp, fail] = __patch__ (h, args{:});
47 if (fail)
48 print_usage();
49 endif
50 htmp (end + 1) = tmp;
51 endfor
52 unwind_protect_cleanup
53 axes (oldh);
54 end_unwind_protect
55
56 if (nargout > 0)
57 retval = htmp;
58 endif
59
60endfunction
61
62function iargs = __find_patches__ (varargin)
63 iargs = [];
64 i = 1;
65 while (i < nargin)
66 iargs (end + 1) = i;
67 if (ischar (varargin{i})
68 && (strcmpi (varargin{i}, "faces")
69 || strcmpi (varargin{i}, "vertices")))
70 i += 4;
71 elseif (isnumeric (varargin{i}))
72 i += 2;
73 endif
74
75 if (i <= nargin)
76 while (true);
77 if (ischar (varargin{i}) &&
78 (strcmpi (varargin{i}, "faces")
79 || strcmpi (varargin{i}, "vertices")))
80 break;
81 elseif (isnumeric (varargin{i}))
82 ## Assume its the colorspec
83 i++;
84 break;
85 elseif (ischar (varargin{i}))
86 colspec = tolower (varargin{i});
87 collen = length (colspec);
88
89 if (strncmp (colspec, "blue", collen)
90 || strncmp (colspec, "black", collen)
91 || strncmp (colspec, "k", collen)
92 || strncmp (colspec, "black", collen)
93 || strncmp (colspec, "red", collen)
94 || strncmp (colspec, "green", collen)
95 || strncmp (colspec, "yellow", collen)
96 || strncmp (colspec, "magenta", collen)
97 || strncmp (colspec, "cyan", collen)
98 || strncmp (colspec, "white", collen))
99 i++;
100 break;
101 endif
102 else
103 i += 2;
104 endif
105 endwhile
106 endif
107 endwhile
108endfunction
109
110%!demo
111%! clf
112%! t1 = (1/16:1/8:1)'*2*pi;
113%! t2 = ((1/16:1/8:1)' + 1/32)*2*pi;
114%! x1 = sin(t1) - 0.8;
115%! y1 = cos(t1);
116%! x2 = sin(t2) + 0.8;
117%! y2 = cos(t2);
118%! h = fill(x1,y1,'r',x2,y2,'g');