ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <schuster.wolfgang@googlemail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Background using Image Overlay
Date: Tue, 8 Nov 2011 06:31:25 +0100	[thread overview]
Message-ID: <1EF34C3F-B50E-49B1-847C-6823AB20D750@googlemail.com> (raw)
In-Reply-To: <CAFy9bANEpWzA9Hr=4LO9t=yUkCoTrt=H7_Lqnm7JKbKny=4d2w@mail.gmail.com>


Am 08.11.2011 um 04:45 schrieb Syed N Haider:

> Hi All
> I am new to the Metapost and Context world, and need some help regarding the inclusion of Metapost graphics in ConTeXt documents. I am trying a very simple approach, using a graphic as a background. Here's my sample (using a very basic metapost graphic as a page background in a document):
> 
> Metapost:
> ========
> beginfig(0);
> theta := 360/7;
> radius := 1in;
> z0 = origin;
> z1 = z0 + dir(90)*radius;
> z2 = z0 + dir(90 + theta)*radius;
> z3 = z0 + dir(90 + 2*theta)*radius;
> z4 = z0 + dir(90 + 3*theta)*radius;
> z5 = z0 + dir(90 + 4*theta)*radius;
> z6 = z0 + dir(90 + 5*theta)*radius;
> z7 = z0 + dir(90 + 6*theta)*radius;
> draw z1 -- z2 -- z3 -- z4 -- z5 -- z6 -- z7
> -- cycle;
> endfig;
> end;
> 
> 
> 
> ConTeXt (after running mpost on the metapost graphic to generate  the hexagon.0 file):
> =====================================================================
> 
> \defineoverlay
> [backg]
> [{\externalfigure[hexagon.0][width=\overlaywidth,height=\overlayheight]}]
> 
> \starttext
> \noheaderandfooterlines
> \setupbackgrounds[page][background=backg]
> %\placefigure
> %{none}
> %{\externalfigure[hexagon.0][width=12cm]}
> \stoptext

With ConTeXt you can include your MetaPost code in the document and the graphic is generated at runtime.

\startuseMPgraphic{hexagon}
theta := 360/7;
radius := 1in;
z0 = origin;
z1 = z0 + dir(90)*radius;
z2 = z0 + dir(90 + theta)*radius;
z3 = z0 + dir(90 + 2*theta)*radius;
z4 = z0 + dir(90 + 3*theta)*radius;
z5 = z0 + dir(90 + 4*theta)*radius;
z6 = z0 + dir(90 + 5*theta)*radius;
z7 = z0 + dir(90 + 6*theta)*radius;
draw (z1 -- z2 -- z3 -- z4 -- z5 -- z6 -- z7 -- cycle) xysized(OverlayWidth,OverlayHeight) ;
\stopuseMPgraphic

\defineoverlay[hexagon][\useMPgraphic{hexagon}]

\setupbackgrounds[page][background=hexagon]

\starttext
\page[empty]
\stoptext

For more information about MetaPost graphics take a look into the MetaFun manual (http://pragma-ade.com/show-man-7.htm) which provides many examples.

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


      reply	other threads:[~2011-11-08  5:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-08  3:45 Syed N Haider
2011-11-08  5:31 ` Wolfgang Schuster [this message]

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=1EF34C3F-B50E-49B1-847C-6823AB20D750@googlemail.com \
    --to=schuster.wolfgang@googlemail.com \
    --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).