Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I searched a bit and didn't find something that relates to this.

Suppose I created a closed curve in Metapost with the command p:=z_1..z_2..z_3..cycle. Is it possible to color pieces of this curve using different colors? How can I define a subset of this curve?

I was thinking that maybe there is a parametric representation of p which would enable me to color with another color the part from z_1 to z_2 for example.

It would really help if I could do the above, because I want to attach other figures to the colored portions of the curve.

Thank you.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

There are many ways to specify parts of a path. One way is to use the cutbefore and cutafter statements as illustrated here:

\starttext
\startMPpage
    % define points
    z_0 := origin;
    z_1 := (0cm, .5cm);
    z_2 := (3cm, 1cm);
    z_3 := (5cm, 3.5cm);
    z_4 := (2cm, 3cm);
    z_5 := (1cm, 2cm);

    % define paths
    path p;
    p := z_1 .. z_2 .. z_3 .. z_4 .. z_5 .. cycle;
    path s;
    s := p cutbefore point 3 of p .. p cutafter point 1 of p;

    % draw lines
    draw p withpen pencircle scaled 8pt withcolor blue;
    draw s withpen pencircle scaled 4pt withcolor yellow;

    % draw the points and labels
    pickup pencircle scaled 8pt;
    for x=0 upto 4:
        draw point x of p;
        label.bot(decimal(x), point x of p);
    endfor;
\stopMPpage
\stoptext

Result:

result

For more information I would suggest reading the MetaFun manual. MetaFun is an extension to MetaPost. Anyhow, there are many examples included (see chapters one and two) that will also work with plain MetaPost.

share|improve this answer
    
Thank you very much. –  Beni Bogosel Mar 12 '12 at 14:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.