tex >> MetaPost default draw color

by tlhiv » Wed, 14 Dec 2005 12:00:22 GMT

What's the best way to make sure that all draw commands use a
particular color (unless otherwise specified)?



tex >> MetaPost default draw color

by tlhiv » Wed, 14 Dec 2005 12:32:39 GMT

Actually, what I want is for entire picture to have a black background
with white strokes. That is, I want to draw white on black by default
instead of black on white.

Is this easily done?



tex >> MetaPost default draw color

by Taco Hoekwater » Wed, 14 Dec 2005 15:40:11 GMT


Hi,



fill, draw, filldraw and drawdot obey the 'drawing options':

beginfig(1);
fill unitsquare scaled 100;
drawoptions(withcolor white); % <=
fill unitsquare scaled 50 shifted (10,10);
pickup pencircle scaled 10;
draw (80,80);
endfig;
end.

Cheers, Taco


tex >> MetaPost default draw color

by tlhiv » Wed, 14 Dec 2005 21:41:33 GMT

Taco,

Thanks for the reply. But I presumably I won't know how much to
initially fill until the drawing is complete. I know about the
drawoptions, but I can't get it to work. Here's what I'm doing:

beginfig(1)
background:=black;
drawoptions(withcolor white);
<some drawing code>
pic:=currentpicture;
currentpicture:=nullpicture;
unfill bbox pic;
draw pic;
endfig

This doesn't operate as I would expect it to. As you can see, I want
the entire background of my picture (i.e. the stuff not already filled)
to be black and all drawn objects to be drawn in white. And I don't
know how much to fill initially until I'm done drawing.



tex >> MetaPost default draw color

by Thomas Path » Wed, 14 Dec 2005 23:55:14 GMT


From "tlhiv" < XXXX@XXXXX.COM >


Something like that :

beginfig(1)
<some drawing code>
picture pic, p;
pic:=currentpicture;
currentpicture:=nullpicture;
fill bbox pic withcolor black;
for p within pic:
draw p withcolor white;
endfor
endfig

??

~Thomas





tex >> MetaPost default draw color

by tlhiv » Thu, 15 Dec 2005 00:20:26 GMT

Thomas,

Thanks for your reply, but it doesn't quite work. Let me provide you
with a specific example:

beginfig
path p,q;
p:=fullcircle scaled 72;
q:=subpath (0,(length p)/2) of p--cycle;
fill q withcolor red;
fill q rotated 180 withcolor blue;
draw p;
endfig

This code will draw a circle that is half filled with red and half
filled with blue. Also, the background is white and the stroke color
for the draw commands is black. What I would like to do is draw the
same picture but have the background be black and the stroke color of
the draw commands be white.



tex >> MetaPost default draw color

by Lars Madsen » Thu, 15 Dec 2005 01:04:41 GMT




beginfig(1);
path p,q;
p:=fullcircle scaled 72;
q:=subpath (0,(length p)/2) of p--cycle;
fill q withcolor red;
fill q rotated 180 withcolor blue;

picture pic;
pic:=currentpicture;
currentpicture:=nullpicture;
fill bbox pic withcolor black;
draw pic;
draw p withcolor white;
endfig;
end;


??

--

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
Superb Class: http://www.ctan.org/tex-archive/help/Catalogue/entries/memoir.html
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal working examples.


tex >> MetaPost default draw color

by tlhiv » Thu, 15 Dec 2005 01:08:13 GMT

Lars,

It appears that according to your solution that if the drawing were
much more complicated, then I'd have to redraw every "draw statement"
in the original drawing with color white. That's unacceptable. I'm
looking for a solution that basically will not force me to have to
redraw individual components of the original picture.



tex >> MetaPost default draw color

by Thomas Path » Thu, 15 Dec 2005 01:11:58 GMT


from "tlhiv" < XXXX@XXXXX.COM >

% Ok, one more test:
picture newpic,varpic;
newpic:=currentpicture;
currentpicture:=nullpicture;
fill bbox newpic withcolor black;
for varpic within newpic:
draw varpic;
draw pathpart varpic withcolor white;
endfor;

~Thomas





tex >> MetaPost default draw color

by tlhiv » Thu, 15 Dec 2005 01:41:09 GMT

Thomas,

This almost works. However, it redraws *every* stroked path white
(including the ones in my drawing that were drawn a different color,
e.g. green). So, let me revise my example to be:

beginfig
path p,q;
p:=fullcircle scaled 72;
q:=subpath (0,(length p)/2) of p--cycle;
fill q withcolor red;
fill q rotated 180 withcolor blue;
draw p;
draw (-36,0)--(36,0) withcolor green;
endfig

I want that green line to stay green and all lines that where black to
be white and the background white to be black.



tex >> MetaPost default draw color

by Taco Hoekwater » Thu, 15 Dec 2005 02:10:49 GMT





This perhaps?

picture pic;
beginfig(1);
drawoptions(withcolor white);
fill unitsquare scaled 50 shifted (10,10);
pickup pencircle scaled 10;
draw (80,80);
pic:=currentpicture;
currentpicture:=nullpicture;
drawoptions(); % clears !
fill bbox pic;
addto currentpicture also pic;
endfig;
end.

? Taco


tex >> MetaPost default draw color

by tlhiv » Thu, 15 Dec 2005 02:16:32 GMT

Taco,

You 'da man. Thanks a bunch.



tex >> MetaPost default draw color

by tlhiv » Thu, 15 Dec 2005 02:24:36 GMT

Now that the problem is solved, for those that are interested, here's
the specific example I was working on:

beginfig(1)
background:=black;
drawoptions(withcolor white);
u:=36;
path p[],q[];
numeric s[],t[];
p1:=fullcircle scaled (2*u) shifted
(-2*u/3*cosd(30),2*u/3*sind(30));
p2:=fullcircle scaled (2*u) shifted (2*u/3*cosd(30),2*u/3*sind(30));
p3:=fullcircle scaled (2*u) shifted (0,-2*u/3);
(s1,t1)= p1 intersectiontimes p2;
(s2,t2)= p1 intersectiontimes p3;
(s3,t3)= p2 intersectiontimes p3;
(s4,t4)= reverse p2 intersectiontimes p1;
(s5,t5)= reverse p1 intersectiontimes p2;
(s6,t6)= reverse p1 intersectiontimes p3;
q1:=(subpath (s1,s2) of p1)--(subpath (t2,t3) of p3)--(subpath
(s3,t1) of p2)--cycle;
q2:=(subpath (t3,t2) of p3)--(subpath (s2,t4) of p1)--(subpath
(t5,s3) of p2)--cycle;
q3:=(subpath (t6,t3) of p3);
q3:=q3--(q3 rotated 120)--(q3 rotated 240)--cycle;
fill q1 withcolor red;
fill q1 rotated -120 withcolor (1,1,0);
fill q1 rotated 120 withcolor blue;
fill q2 withcolor (1/2,0,1/2);
fill q2 rotated -120 withcolor (1,1/2,0);
fill q2 rotated 120 withcolor green;
fill q3 withcolor white;
draw p1;
draw p2;
draw p3;
picture pic;
pic:=currentpicture;
currentpicture:=nullpicture;
drawoptions();
unfill bbox pic;
addto currentpicture also pic;
endfig

If you have any comments regarding this graphic, let me know. I think
it's a beauty (but then I'm biased).

Thanks again folks!



tex >> MetaPost default draw color

by Dan » Thu, 15 Dec 2005 06:28:48 GMT




I am mystified by all the folderall you caused. I can get exactly the
same picture with the following obvious scheme, making no changes at
all to background or drawoptions: draw it in the color you want
(basically as is except draw the three circles in white). Copy the
result to pic, erase currentpicture, add the black square and copy pic
on top.

If you want to make things more general (e.g., devise a scheme for
reversing black and white for drawing), simply use a descriptive name
for the color and redefine when necessary:

color drawcolor;
drawcolor:=black;
drawoptions {withcolor drawcolor);
...
draw p1;
draw p1;
...
drawcolor:=white;
draw q1;
draw q2;
...

This scheme is the same as provided in plain.mp for unfill, except the
"withcolor background" has been hard coded into the definition of
unfill instead of being added with drawoptions.


Dan



tex >> MetaPost default draw color

by tlhiv » Thu, 15 Dec 2005 06:48:48 GMT

Dan,

Thanks for those kind words. The point (independent of this particular
drawing) is that it should be pretty straightforward to change the
default background of a figure. MetaPost uses "background" to apply to
"unfill" and "undraw" only. There should be a way to tell MetaPost ...
"from this point forward, everything drawn should be of color <x,y,z>
sitting on top of a background of color <u,v,w>".

I am pleased with the solution that Taco provided.



Similar Threads

1. Change default metapost font

I know infont can change what font to use when drawing text in metapost

But what's the name of other fonts besides the default one?

I've tried "Times-Roman" just like the metapost manual says, but it
doesn't work, the output say:

"makemf" --verbose "Times-Roman"
"hbf2gf" -q -g "Times-Roman" 300
maketfm: No creation rule for font "Times-Roman".
! Font Times-Roman not usable: TFM file not found.

I also tried "times", it doesn't work either :(

Anyone could help me?

Thanks in advance!

2. MetaPost: default value for the macro ?

3. Why can not display lable in the figure drawn by metapost in texlive2007

Hi,all,
I am learning MEATPOST, and just type the following code in a file named 
fig.mp

%%% fig.mp file%%%%%%%%%%%%
beginfig(1);
   a=.7in;b=.5in;
   z0=(0,0);
   z1=-z3=(a,0);
   z2=-z4=(0,b);
   draw z1..z2..z3..z4..cycle;
   draw z1--z0--z2;
   label.top("a",.5[z0,z1]);
   label.lft("b",.5[z0,z2]);
   dotlabel.bot("(0,0)",z0);
endfig;
end

%%%%%%%%%%% end file %%%%%%%%%%

This is an example of "A user's manual for MetaPost"(John D.Hobby) in chaper 
7 page 19.

But when I run by emacs23
mpost fig.mp

It seems ok.
Yet there is nothing in the file of fig.1.I mean it is all blank.
I don't know the reason.

Thank you for your help.





4. metapost draw with hyperlink

5. Axis gap [WAS: drawing on frame in metapost graph]

6. drawing on frame in metapost graph

7. [MetaPost] transparent drawing with metaobj

Hello,

as the example below shows, metaobj draws objects opaque using
backgroundcolor (if not fillcolor). Is there any way to draw objects
transparent, i.e. don unfill the picure before drawing it? I couldn
find an option.

Regards,
Stephan Hennig


input metaObj;
prologues:=1;
beginfig(1);
newCircle.A("text text");
newCircle.B("") "circmargin(8bp)";
A.c = origin;
B.c = A.c;
drawObj(A,B);
endfig;
end

8. changing default text and formulas color