The easiest way to draw a
Path is with no arguments.
Point pt; pt.set(-1, -2); pt.set(0, -3); pt.set(1, 0); pt.set(2, 1); pt.set(-1, 2); Path pa("..", true, &pt, &pt, &pt, &pt, &pt, 0); pa.draw();
pa is closed, it can be filled as well as drawn. The
following example uses
fill() with a
Color argument, in
order to avoid having a large splotch of black on the page.
Colors are declared in the
See Color Reference.
Paths can be filled and drawn, using the function
filldraw(). This function draws the
Path using the pen
specified, or MetaPost's
currentpen by default. A
for drawing the
Path can also be specified, otherwise, the
default color (currently
Colors::black) is used.
In addition, the
Path is filled using a second
which can be specified, or the background_color
Colors::background_color), by default.
Path using the background color causes it to hide
objects that lie behind it.
See Surface Hiding, for a description of the surface hiding
algorithm, and examples. Currently, this algorithm is quite primitive
and only works
for simple cases.
Point p0(-3, 0, 1); Point p1(3, 1, 1); p0.draw(p1); pa.filldraw();
The following example uses arguments for the
Colors used for
drawing and filling, and the pen. The empty string argument before the
pen argument is a placeholder for the dash pattern argument.
pa.filldraw(black, gray, "", "pensquare xscaled 3mm yscaled 1mm rotated 60");
Paths can also be "undrawn", "unfilled", and "unfilldrawn",
using the corresponding functions:
pa.fill(gray); p0.undraw(p1, "", "pencircle scaled 3mm");
pa.fill(gray); Path q; q = pa; q.scale(.5, .5); q.unfill();
unfilldraw() takes a
Color argument for
Path, which is
default. This makes it possible to unfill the
Path while drawing
the outline with a visible
Color. On the other hand, it also
makes it necessary to specify
Colors::white, if the user wants to use the dash pattern and/or
pen arguments, without drawing the
pa.fill(gray); q.unfilldraw(white, "", "pensquare xscaled 3mm yscaled 1mm");
The following example demonstrates the use of
black as its
Color argument. Unfortunately, it also
demonstrates one of the limitations of the surface hiding algorith: The
p1 is hidden by the
Path pa. Since the portion of
pa covered by
Path q has been unfilled,
the line from p_0 to p_1
should be visible as it passes through
q. However, from the
point of view of 3DLDF, there is no relationship between
q; nor does it "know" whether a
Path has been filled or
unfilled. If it's on a
Picture, it will hide objects lying
behind it, unless the surface hiding algorithm fails for another
reason. See Surface Hiding, for more information.
p0.draw(p1); pa.fill(gray); q.unfilldraw(black, "", "pensquare xscaled 3mm yscaled 1mm");
See Paths; Drawing and Filling, for more information, and complete descriptions of the functions.