5

The question may be trivial, but I need your help, to draw a full colored triangle and circle (where the triangle will be inside the circle).

Here is my file pic_1.mp:

input gjktc.mp;

u:=1mm;

beginfig(1);

z0=(0,0);
z1=(20u,0);
z2=(10u,20u);

draw z0..z1..z2..cycle withcolor green;
draw z0--z1--z2--cycle withcolor red;
endfig;
end;

And the next one, pic_2.mp, where the one line will be rotated, and the space between lines will be colored:

input gjktc.mp;

u:=1mm;

beginfig(1);

z0=(0,0);
z1=(20u,0);
z2=(10u,10u);

p1 = z0--z1--z2--cycle ;
draw p1 withcolor black;
draw (z2--z0) rotated 5 withcolor black;

endfig;
end;

Here is a picture of what I want to have:

enter image description here

  • 2
    You need the "fill" command. Otherwise most of the code looks roughly what is required. (More specific: where you have "draw ... withcolor ..." try "fill ... withcolor ..." – Andrew Kepert Nov 3 '13 at 21:01
  • Thank you. That is exactly what I need. And if you will see at the second picture, there is black lines and spaces are colored differently. I have a problem with red part. I have something like this, but it is doesnt work. p2= (z2--z0) rotated 5; draw p2 withcolor black; fill p2--z2 withcolor blue; – Dominika Nov 3 '13 at 21:25
6
prologues := 3;        % Make metapost write EPS files
u := 1mm;

outputtemplate := "pic%c.eps";  % set the filename template - %c picks up the fig #

beginfig(1);
z0=(10u,0) rotated 90;  % use "rotated" to get a nice equilateral triangle easily
z1=z0 rotated 120; z2 = z0 rotated -120;
fill z0..z1..z2..cycle withcolor green; 
fill z0--z1--z2--cycle withcolor red;
endfig;

beginfig(2);  % second fig can be in the same file 
z0=(0,0);
z1=(20u,0);
z2=(10u,10u);
z3 = whatever[z0,z2 rotated 5] = whatever[z1,z2]; % read mpman.pdf for "whatever"

path p[];  % you must declare paths
p1 = z0--z1--z2--cycle;
p2 = z0--z2--z3--cycle;

fill p1 withcolor green;  % fill before you draw (in general)
fill p2 withcolor red;
draw p1 withcolor black;
draw p2 withcolor black;

endfig;
end;

I've added some notes as comments in the code.

pic1.eps = enter image description here pic2.eps = enter image description here

  • 1
    You should use outputtemplate instead of filenametemplate (the latter is considered deprecated since MetaPost version 1.200). – karlkoeller Nov 4 '13 at 6:11
  • @karlkoeller thanks, will fix. Old habits die hard. – Thruston Nov 5 '13 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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