4.2 fill

void fill(picture pic=currentpicture, path g, pen p=currentpen);

Fill the interior region bounded by the cyclic path g on the picture pic, using the pen p.

There is also a convenient filldraw command, which fills the path and then draws in the boundary. One can specify separate pens for each operation:

void filldraw(picture pic=currentpicture, path g, pen fillpen=currentpen,
              pen drawpen=currentpen);

This fixed-size version of fill allows one to fill an object described in PostScript coordinates about the user coordinate origin:

void fill(pair origin, picture pic=currentpicture, path g, pen p=currentpen);

This is just a convenient abbreviation for the commands:

picture opic;
fill(opic,g,p);
add(pic,opic,origin);

The routine

void filloutside(picture pic=currentpicture, path g, pen p=currentpen);

fills the region exterior to the path g, out to the current boundary of picture pic.

Lattice gradient shading varying smoothly over a two-dimensional array of pens p, using fill rule fillrule, can be produced with

void latticeshade(picture pic=currentpicture, path g, bool stroke=false,
                  pen fillrule=currentpen, pen[][] p)

If stroke=true, the region filled is the same as the region that would be drawn by draw(pic,g,zerowinding); in this case the path g need not be cyclic. The pens in p must belong to the same color space. One can use the functions rgb(pen) or cmyk(pen) to promote pens to a higher color space, as illustrated in the example file latticeshading.asy.

Axial gradient shading varying smoothly from pena to penb in the direction of the line segment a--b can be achieved with

void axialshade(picture pic=currentpicture, path g, bool stroke=false,
                pen pena, pair a, bool extenda=true,
                pen penb, pair b, bool extendb=true);

The boolean parameters extenda and extendb indicate whether the shading should extend beyond the axis endpoints a and b. An example of axial shading is provided in the example file axialshade.asy.

Radial gradient shading varying smoothly from pena on the circle with center a and radius ra to penb on the circle with center b and radius rb is similar:

void radialshade(picture pic=currentpicture, path g, bool stroke=false,
                 pen pena, pair a, real ra, bool extenda=true,
                 pen penb, pair b, real rb, bool extendb=true);

The boolean parameters extenda and extendb indicate whether the shading should extend beyond the radii a and b. Illustrations of radial shading are provided in the example files shade.asy, ring.asy, and shadestroke.asy.

Gouraud shading using fill rule fillrule and the vertex colors in the pen array p on a triangular lattice defined by the vertices z and edge flags edges is implemented with

void gouraudshade(picture pic=currentpicture, path g, bool stroke=false,
                  pen fillrule=currentpen, pen[] p, pair[] z,
                  int[] edges);
void gouraudshade(picture pic=currentpicture, path g, bool stroke=false,
                  pen fillrule=currentpen, pen[] p, int[] edges);

In the second form, the elements of z are taken to be successive nodes of path g. The pens in p must belong to the same color space. Illustrations of Gouraud shading are provided in the example file Gouraud.asy. The edge flags used in Gouraud shading are documented on pages 270–274 of the PostScript Language Reference (3rd edition):

https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf

Tensor product shading using clipping path g, fill rule fillrule on patches bounded by the n cyclic paths of length 4 in path array b, using the vertex colors specified in the n \times 4 pen array p and internal control points in the n \times 4 array z, is implemented with

void tensorshade(picture pic=currentpicture, path[] g, bool stroke=false,
                 pen fillrule=currentpen, pen[][] p, path[] b=g,
                 pair[][] z=new pair[][]);

If the array z is empty, Coons shading, in which the color control points are calculated automatically, is used. The pens in p must belong to the same color space. A simpler interface for the case of a single patch (n=1) is also available:

void tensorshade(picture pic=currentpicture, path g, bool stroke=false,
                 pen fillrule=currentpen, pen[] p, path b=g,
                 pair[] z=new pair[]);

One can also smoothly shade the regions between consecutive paths of a sequence using a given array of pens:

void draw(picture pic=currentpicture, pen fillrule=currentpen, path[] g,
          pen[] p);

Illustrations of tensor product and Coons shading are provided in the example files tensor.asy, Coons.asy, BezierPatch.asy, and rainbow.asy.

More general shading possibilities are available using TeX engines that produce PDF output (see texengines): the routine

void functionshade(picture pic=currentpicture, path[] g, bool stroke=false,
                   pen fillrule=currentpen, string shader);

shades on picture pic the interior of path g according to fill rule fillrule using the PostScript calculator routine specified by the string shader; this routine takes 2 arguments, each in [0,1], and returns colors(fillrule).length color components. Function shading is illustrated in the example functionshading.asy.

The following routine uses evenodd clipping together with the ^^ operator to unfill a region:

void unfill(picture pic=currentpicture, path g);