Metapost - Color portions of a curve with different colors

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.

-

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:

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.

-
Thank you very much. – Beni Bogosel Mar 12 '12 at 14:16