23.10.2014 Views

mfpic-doc.pdf.

mfpic-doc.pdf.

mfpic-doc.pdf.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.5 RENDERING FIGURES. 40<br />

This example will start the gradient with red and end it with blue. For an angle of 0 the starting color<br />

is at the bottom and the ending color at the top, for other angles simply rotate that description. The<br />

above circle will be red at the lower right and blue at the upper left.<br />

This type of gradient is called an axial gradient. The following is another kind, based on a color<br />

function of two variables over an area.<br />

\areagradient{〈clrfcn〉,〈h-dim〉,〈v-dim〉}...<br />

Instead of filling with strips of different colors, \areagradient fills with “pixels” of different<br />

colors. These are rectangles that have size 〈h-dim〉 by 〈v-dim〉, which values must be specified in<br />

absolute units. These rectangles are filled with the color determined by 〈clrfcn〉. This must be a<br />

function of two parameters that returns a color for values of these parameters from 0 to 1 (inclusive).<br />

For example,<br />

\fdef{agr}{t,u}%<br />

{(1-t)(1-u)*white + (1-t)*u*red + t*(1-u)*green + t*u*blue}<br />

\gradient{agr,3pt,4pt}\rect{(0,0),(1,2)}<br />

The color returned for (0,0) is at the lower left and the color returned for (1,1) is at the upper right.<br />

In the above example, the rectangle will be white at the lower left, red at the upper left, green at the<br />

lower right and blue at the upper right.<br />

Our last gradient is something like the first, but in polar coordinates. The colors vary with the<br />

distance from a center point.<br />

\radialgradient{〈clrfcn〉,〈width〉,〈center〉}...<br />

This gradient fills with concentric circular strips whose center is 〈center〉 and whose thickness<br />

is 〈width〉. The 〈clrfcn〉 is as in \gradient. The circle of radius 〈width〉 and center 〈center〉 is filled<br />

with the color returned for parameter value 0. The largest concentric circular strip is filled with the<br />

color returned for parameter value 1.<br />

These commands all initially compute a bounding figure for the curve. In the first case it is a<br />

rotated rectangle, in the second case an upright rectangle, and in the third case a circle centered at<br />

the given point. The interiors of the rectangles are considered to have coordinates (t,u) that vary<br />

from (0,0) at the lower left to (1,1) at the upper right. The inside of the circle is considered to have<br />

the polar coordinate r ranging from 0 at the center to 1 at the boundary. The relevant coordinate(s)<br />

are fed to the specified 〈clrfcn〉 and the returned color is used to fill the relevant portion of the<br />

rectangle or circle. The whole picture is then clipped to the boundaries of the given closed curve and<br />

the result added to the picture.<br />

The process is somewhat wasteful of memory in METAPOST, as each strip or pixel’s path is<br />

kept in memory and written to the output file. This can be quite large for \areagradient if the<br />

pixel dimensions are too small. For example, covering a one inch square with pixels 1 point on each<br />

side takes over 5000 paths and the resulting EPS is over 100,000 bytes in size. I would recommend<br />

dimensions on the order of 2 to 3 points. Larger dimensions are not as visually appealing, and smaller<br />

dimensions waste memory with little improvement in appearence.<br />

This command works in METAFONT using a 〈clrfcn〉 that returns numeric values in the range 0 to<br />

1. The result is much like \gfill[〈clr〉] (see the beginning of this section) except the dots simulating<br />

a gray fill will vary in size corresponding to the 〈clrfcn〉. The result will be disappointing unless<br />

there is considerable contrast between the lightest and darkest grays of the gradient. Therefore, it is<br />

recommended that the color function cover the entire range from 0 to 1 (black to white). There are<br />

no particular memory problems with gradients in METAFONT, at least no more so than gray fills.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!