29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Because of this implementation, shading may behave somewhat unexpected at times. A rather<br />

normal case is the next one, where we place 5 shaded circles in a row.<br />

path p ; p := fullcircle scaled 1cm ;<br />

for i=0 step 2cm until 8cm :<br />

circular_shade(p shifted (i,0),0,\MPcolor{a},\MPcolor{b}) ;<br />

endfor ;<br />

At first sight, in the next situation, we would expect something similar, because we simply copy<br />

the same circle 5 times. However, due to the way we have implemented shading in CONTEXT, we do<br />

indeed copy the circles, but the shade definition is frozen and the same one is used for all 5 circles.<br />

This means that the center of the shading stays at the first circle.<br />

circular_shade(fullcircle scaled 1cm,0,\MPcolor{a},\MPcolor{b}) ;<br />

picture s ; s := currentpicture ; currentpicture := nullpicture ;<br />

for i=0 step 2cm until 8cm :<br />

addto currentpicture also s shifted (i,0) ;<br />

endfor ;<br />

Unlike TEX, METAPOST does not keep its specials attached to the current path, and flushes them<br />

before the graphic data. Since we use these specials to register shading information, it is rather<br />

hard to tightly connect a specific shade with a certain fill, especially if an already performed fill is<br />

not accessible, which is the case when we copy a picture.<br />

This may seem a disadvantage, but fortunately it also has its positive side. In the next example<br />

we don't copy, but reuse an already defined shade. By storing the reference to this shade, and<br />

referring to it by using withshade, we can use a shade that operates on multiple shapes.<br />

sh := define_circular_shade<br />

(origin,origin,0,8cm,\MPcolor{a},\MPcolor{b}) ;<br />

for i=0 step 2cm until 8cm :<br />

fill fullcircle scaled 1cm shifted (i,0) withshade sh ;<br />

endfor ;<br />

The low level macro define_circular_shade is fed with two pairs (points), two radius, and two<br />

colors. The shade is distributed between the colors according to the radius.<br />

Shading can hardly be called an easy issue. The macros that we provide here are in fact simplifications,<br />

which means that at a lower level, one can do more advanced things. Here we limit<br />

ourselves to the more common cases. In the previous examples, we used an arrow to indicate the<br />

Shading Special effects<br />

187

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

Saved successfully!

Ooh no, something went wrong!