29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

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.

40<br />

1.13 Colors<br />

So far, we have seen some colors in graphics. It must be said that METAPOST color model is not that<br />

advanced, although playing with colors in the METAPOST way can be fun. In later chapters we will<br />

discuss some extensions that provide shading.<br />

Colors are defined as vectors with three components: a red, green and blue one. Like pens, colors<br />

have their with--command:<br />

withcolor (.4,.5.,6)<br />

You can define color variables, like:<br />

color darkred ; darkred := (.625,0.0) ;<br />

You can now use this color as:<br />

withcolor darkred<br />

Given that red is already defined, we also could have said:<br />

withcolor .625red<br />

Because for METAPOST colors are just vectors, you can do things similar to points. A color halfway<br />

red and green is therefore accomplished with:<br />

withcolor .5[red,green]<br />

Since only the RGB color space is supported, this is about all we can tell about colors for this moment.<br />

Later we will discuss some nasty details.<br />

1.14 Dashes<br />

A dash pattern is a simple picture that is build out of straight lines. Any slightly more complicated<br />

picture will be reduced to straight lines and a real complicated one is rejected, and in this respect<br />

METAPOST considers a circle to be a complicated path.<br />

The next example demonstrates how to get a dashed line. First we built picture p, that we apply<br />

to a path. Here we use a straight path, but dashing can be applied to any path.<br />

picture p ; p := nullpicture ;<br />

addto p doublepath ((0,0)--(3mm,3mm)) shifted (6mm,6mm) ;<br />

draw (0,0)--(10cm,0) dashed p withpen pencircle scaled 1mm ;<br />

This way of defining a pattern is not that handy, especially if you start wondering why you need<br />

to supply a slanted path. Therefore, METAPOST provides a more convenient mechanism to define a<br />

pattern.<br />

picture p ; p := dashpattern(on 3mm off 3mm) ;<br />

draw (0,0)--(10cm,0) dashed p withpen pencircle scaled 1mm ;<br />

Welcome to MetaPost Colors

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

Saved successfully!

Ooh no, something went wrong!