ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
Subject: Re: Metapost label alignment etc.
Date: Wed, 5 Jul 2006 18:27:04 -0400 (EDT)	[thread overview]
Message-ID: <Pine.WNT.4.63.0607051822550.2516@nqvgln> (raw)
In-Reply-To: <op.tbzm6dlynx1yh1@walayah-main>

On Fri, 30 Jun 2006, Idris Samawi Hamid wrote:

> Hi, Mojca, Aditya, Hans, and all the MP gurus,
>
> Thank you for all the help and advice.
>
> On Fri, 30 Jun 2006 18:17:23 -0600, Mojca Miklavec
> <mojca.miklavec.lists@gmail.com> wrote:
>
> Wow... Ok, following is my present, still naive code. What I would like to
> be able to do is
>
> 1) In the first figure [square], control the relation of the front and
> back face of the cube by a single parameter. So if I use z for the front
> face coordinates, I can use z' for the rear face and define z' as a
> function of z. Then the angle of the z111--z'111 diagonal wrt the x-axis
> will change, and the label for that axis will have to change as well. I've
> been manually calculating inverse tangents to do this but can it be done
> automatically?

angle(...).


> 2. In the second figure, to in addition control the distance between the 2
> cubes by a single parameter without recalculating the dashed lines mapping
> the two.

See code below.

> I only started yesterday but i can see that MetaPost is going to turn me
> into a junkie if I'm not careful :-)
>
> Any other suggestions for improving/streamlining this is greatly
> appreciated: I think it will make a nice example case for beginners/on the
> wiki when done!

I do not have an ingeneous solution like Mojca. I will do this in a 
brute force way like you, but using loops for repetitive tasks and 
allowing metapost to do all the calculations for me.

\setuppapersize[letter][letter]
\setupcolors[state=start]
\setuppagenumbering[state=stop]

\def\AXIS#1#2#3{(#1) Axis #2: {\bf #3}}

\forceMPTEXcheck{LABELL}
\forceMPTEXcheck{LABELR}
\forceMPTEXcheck{LABELM}

\startMPenvironment
      \ssxx\setupinterlinespace
\stopMPenvironment

\startMPinclusions
   vardef LABELL@\#(expr s, p)= label@\#(textext("%
   \framed[width=1.5cm,align=left,frame=off,autowidth=force,strut=on]{" 
& s &
   "}"),p)
   enddef ;

vardef LABELR@\#(expr s, p)= label@\#(textext("%
\framed[width=1.5cm,align=right,frame=off,autowidth=force,strut=on]{" 
& s
& "}"),p)
enddef ;

vardef LABELM@\#(expr s, p)= label@\#(textext("%
\framed[align=middle,frame=off,autowidth=force,strut=on]{" & s & 
"}"),p)
enddef ;

picture my_dash ; my_dash := dashpattern(on 1mm off 1mm) ;

% my_dash is more verbose than p.

\stopMPinclusions

\startstaticMPfigure{square}
   numeric u ; u := 1.4cm;
   % Always declare the type of a variable. Helps in debugging.

   path p; p := unitsquare scaled 5u ;
   % Identify the corners
   z[1] = llcorner p ;
   z[2] = ulcorner p ;
   z[3] = urcorner p ;
   z[4] = lrcorner p ;
   % Identify the corners of the shifted rectangle
   for i = 5 upto 8:
     z[i] = z[i-4] shifted (2u, 1.25u) ;
   endfor ;
   % Find the intersection points
   z[9]  = whatever[z[5],z[6]] = whatever[z[2],z[3]] ;
   z[10] = whatever[z[5],z[8]] = whatever[z[3],z[4]] ;
   % Axis location
   % No need to calculate these explicitly, you can as well use
   % label(p, 0.5[...]) ;
   z[11] = 0.5[z[1],z[4]] ;
   z[12] = 0.5[z[1],z[2]] ;
   z[13] = 0.5[z[1],z[5]] ;
   %  z[13] = (1u,0.15u) ; Not sure which point you had calculated.

  drawoptions(withcolor .625red withpen pencircle scaled 0.4pt) ;

  draw p ;
  draw (z[6]  -- z[7]) ;
  draw (z[7]  -- z[8]) ;
  draw (z[6]  -- z[9]) ;
  draw (z[10] -- z[8]) ;
%  draw (z[2]  -- z[6]) ;
%  draw (z[3]  -- z[7]) ;
%  draw (z[4]  -- z[8]) ;
  for i = 2 upto 4 :
    draw(z[i] -- z[i+4]) ;
  endfor ;
  drawoptions(withcolor .625red dashed my_dash withpen pencircle scaled 
0.4pt) ;

%  draw (z[1] -- z[5])  ;
%  draw (z[9] -- z[5])  ;
%  draw (z[5] -- z[10]) ;
  for i = 1,9,10 :
   draw(z[5] -- z[i] ) ;
  endfor ;

  drawoptions(withcolor black) ;
  LABELL.llft("(0,0,0,0) Light Condensed Small Sans~Serif", z[1]) ;
  LABELL.llft("(0,1,0,0) Light Extended  Small Sans~Serif", z[2]) ;
  LABELR.lrt ("(1,1,0,0) Bold  Extended  Small Sans~Serif", z[3]) ;
  LABELR.lrt ("(1,0,0,0) Bold  Condensed Small Sans~Serif", z[4]) ;

  LABELR.urt("(0,0,1,0)  Light Condensed Large Sans~Serif", z[5]) ;
  LABELR.urt("(0,1,1,0)  Light Extended  Large Sans~Serif", z[6]) ;
  LABELR.urt("(1,1,1,0)  Bold  Extended  Large Sans~Serif", z[7]) ;
  LABELR.urt("(1,0,1,0)  Bold  Condensed Large Sans~Serif", z[8]) ;

  LABELM.bot ("\AXIS{x}{1}{Weight}", z[11]);

  picture p; p :=
  textext("\framed[align=middle,frame=off,autowidth=force,strut=on]%
                            {\AXIS{y}{2}{Width}}");
  p := p rotatedaround (z[12], 90) ;

  label.lft(p,z[12]);

  p := textext("\AXIS{z}{3}{Optical Size}");
  p := p rotatedaround (z[13], angle(z[5]-z[1])) ;
  % inv tan(1.5/2)
  % Let metapost calculate it for you

  % Ugly kludge
  label(p,z[13]+(0,2labeloffset));

%  currentpicture := currentpicture scaled 0.9 ;
%  Why? Either change u, or use scaled= option in \usestaticMPfigure

\stopstaticMPfigure



  \startstaticMPfigure{2squares}

   numeric u ; u := 0.7cm;
   path p; p := unitsquare scaled 5u ;
   % Identify the corners
   z[1] = llcorner p ;
   z[2] = ulcorner p ;
   z[3] = urcorner p ;
   z[4] = lrcorner p ;
   % Identify the corners of the shifted rectangle
   for i = 5 upto 8:
     z[i] = z[i-4] shifted (2u, 1.25u) ;
   endfor ;

   for i = 11 upto 18:
     z[i] = z[i-10] shifted (10u,-2.5u) ;
   endfor ;

  z[19]  = (3.125u,3.125u) ;
  z[20]  = (13.125u,0.625u) ;
  z[21]  = (5u,-1.25u) ;

  drawoptions(withcolor .625red withpen pencircle scaled 0.4pt) ;

for i = 0,10:
  draw (z[i+1]  -- z[i+2] -- z[i+3] -- z[i+4] -- cycle) ;
  draw (z[i+5]  -- z[i+6] -- z[i+7] -- z[i+8] -- cycle) ;
  draw (z[i+1] -- z[i+5]) ;
  draw (z[i+2] -- z[i+6]) ;
  draw (z[i+3] -- z[i+7]) ;
  draw (z[i+4] -- z[i+8]) ;
endfor ;

% Remove repetitions
%  draw (z[11]  -- z[12] -- z[13] -- z[14] -- cycle) ;
%  draw (z[15]  -- z[16] -- z[17] -- z[18] -- cycle) ;
%  draw (z[11] -- z[15]) ;
%  draw (z[12] -- z[16]) ;
%  draw (z[13] -- z[17]) ;
%  draw (z[14] -- z[18]) ;


  % map square to square

  drawoptions(withcolor .625red dashed my_dash withpen pencircle scaled 
0.4pt) ;
  for i = 1 upto 8 :
   draw z[i] -- z[i+10] ;
  endfor ;

%  draw (z[1] -- z[11]) ;
%  draw (z[2] -- z[12]) ;
%  draw (z[3] -- z[13]) ;
%  draw (z[4] -- z[14]) ;
%  draw (z[5] -- z[15]) ;
%  draw (z[6] -- z[16]) ;
%  draw (z[7] -- z[17]) ;
%  draw (z[8] -- z[18]) ;

  % labels

  drawoptions(withcolor black) ;

  label (textext("Sans Serif"),z[19]) ;
  label (textext("Serif"),z[20]) ;

  picture p; p := textext("\AXIS{a}{4}{Serif}");
%  p := p rotatedaround (z[21], -14.036) ;
  p := p rotatedaround (z[21], angle(z[11]-z[1])) ;

  label.bot(p,z[21]);

%  currentpicture := currentpicture scaled 0.9 ;

  \stopstaticMPfigure

\starttext

  \midaligned{\usestaticMPfigure[square]}

  \blank[2*big]

  \midaligned{\usestaticMPfigure[2squares]}

  \stoptext

Aditya

  parent reply	other threads:[~2006-07-05 22:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-30  3:42 Idris Samawi Hamid
2006-06-30  5:42 ` Aditya Mahajan
2006-06-30 20:09   ` Idris Samawi Hamid
2006-06-30 20:54   ` Idris Samawi Hamid
2006-06-30 21:41     ` Hans Hagen
2006-06-30 23:36       ` Idris Samawi Hamid
2006-07-01  0:17         ` Mojca Miklavec
2006-07-01  2:14           ` Idris Samawi Hamid
2006-07-01  4:33             ` Mojca Miklavec
2006-07-01 18:11               ` Idris Samawi Hamid
2006-07-05 22:27             ` Aditya Mahajan [this message]
2006-07-06  5:11               ` Idris Samawi Hamid
2006-07-06 14:39                 ` Mojca Miklavec
2006-07-07  0:35                   ` Idris Samawi Hamid
2006-07-06 13:10               ` Aditya Mahajan
2006-06-30 21:42   ` Idris Samawi Hamid
2006-06-30 22:20   ` More Metapost alignment Idris Samawi Hamid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.WNT.4.63.0607051822550.2516@nqvgln \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).