ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Peter Rolf <indiego@gmx.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Mari Voipio <mari.voipio@iki.fi>
Subject: Re: Metapost/Metafun Q: using variables and "building blocks"?
Date: Tue, 01 May 2012 19:09:14 +0200	[thread overview]
Message-ID: <4FA018BA.6000707@gmx.net> (raw)
In-Reply-To: <CAGbDsP0XzJayWZ6vJY3RQ97eWVbYtCZVsmzeG1z_LXgiBAwFyA@mail.gmail.com>

Hi Mari,

Am 30.04.2012 23:40, schrieb Mari Voipio:
> On Mon, Apr 23, 2012 at 20:34, Mari Voipio <mari.voipio@iki.fi> wrote:
>> a) I need to be able to stack four of these on top of each other and
>> then four mirrored ones next to them
> 
> OK, I really was being stupid - I had already managed to do a "shift"
> inside a single 'block', somehow I just didn't see that I could do the
> same to the blocks:
> 
> 
> 
> \startMPpage
> 
> 
> picture ll ; % left-hand loop
> ll :=
> 	image (
> 		path p, q, r ;
> 
> 		p := fullcircle scaled 4mm ;
> 		q := p shifted (0mm,10mm) ;
> 		r := center p .. (5mm,5mm) .. center q ;
> 
> 		pair pr, qr ;
> 
> 		pr := p intersectionpoint r ;
> 		qr := q intersectionpoint r ;
> 
> 		r := r cutbefore pr cutafter qr ;
> 		r := r cutends 0.2mm ;
> 
> 		draw r withpen pencircle scaled 0.2mm withcolor black ; % the connecting curve
> 		draw p withpen pencircle scaled 0.2mm withcolor black ; fill p
> withcolor black ; % upper shank
> 		draw q withpen pencircle scaled 0.2mm withcolor black ; fill q
> withcolor black ; % lower shank
> 		);
> 
> 
> draw ll ;
> draw ll shifted (0mm,20mm) ;
> draw ll shifted (0mm,40mm) ;
> draw ll shifted (0mm,60mm) ;
> 
> 
> \stopMPpage
> 
> 
>> Keeping in mind that I
>> will have to be able to draw a path/arrow on top, so I need to know
>> where they are.
> 
> My little brain got an overflow from all this abstract thinking, but
> then it dawned on me that I could use the millimeter grid recipe in
> the MetaFun manual (p. 214) to draw a grid behind my pattern drawing.
> Now placing the arrows should be a walk in the park...
> 
> 
> 
>> b) The circles p and q can be filled with the same colour or two
>> different colours, and each of the blocks in a pattern can have
>> different fill colour
>>
>> I assume the answer is "use variables", but how?
> 
> Gaah, I still cannot figure it out!
> A real example: one of my own patterns has white up and down on first
> loop, black up white down on second, white up and down on third and
> blue up and down on fourth. So I'd need
> 
> draw ll ; % and fill both circles with white
> draw ll shifted (0mm,20mm) ; % and fill lower circle with white,
> shifted/upper circle with black
> draw ll shifted (0mm,40mm) ; % fill both circles with white
> draw ll shifted (0mm,60mm) ; % fill both circles with blue
>
> 
> What is the shortest way of doing this? I don't mind writing
> definitions earlier in the file, but I'd rather keep this part as
> short as possible to be able to see the pattern at one glance. The
> main problem comes from the bicoloured loops as I can't just apply the
> same fill on both. And on the whole I'd prefer to make sure I apply
> the fill only locally per each half-loop and not all over the place...
>
donno what is the shortest way, but this looks at least handy...


\startMPinclusions

patternsize:= 20mm;

def lhl(expr ca,cb,sx,sy) =
     picture lefthandloop;
     lefthandloop := image (
         path p, q, r ;
         p := fullcircle scaled 4mm ;
         q := p shifted (0mm,10mm) ;
         r := center p .. (5mm,5mm) .. center q ;
         r := r cutbefore (p intersectionpoint r) cutafter (q
intersectionpoint r) ;

         draw r withpen pencircle scaled 0.2mm withcolor black ; % the
connecting curve
         fill p withcolor ca;
         draw p withpen pencircle scaled 0.2mm withcolor black ; % upper
shank
         fill q withcolor cb;
         draw q withpen pencircle scaled 0.2mm withcolor black ; % lower
shank
         );
     draw lefthandloop shifted (sx*patternsize,sy*patternsize);
enddef;

\stopMPinclusions


\startMPpage

lhl(white,white,0,0);
lhl(white,black,0,1);
lhl(white,white,0,2);
lhl(blue ,blue ,0,3);

\stopMPpage




Best wishes, Peter
___________________________________________________________________________________
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:[~2012-05-01 17:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-23 17:34 Mari Voipio
2012-04-23 18:04 ` Hans Hagen
2012-05-06  8:53   ` Mari Voipio
2012-05-06  9:05     ` Mari Voipio
2012-05-06  9:16     ` luigi scarso
2012-05-06  9:56       ` Wolfgang Schuster
2012-05-06 10:17         ` luigi scarso
2012-05-06 11:33         ` Pontus Lurcock
2012-05-06 12:30           ` Hans Hagen
2012-05-06 12:47     ` Hans Hagen
2012-05-06 12:53       ` Martin Schröder
2012-05-06 12:59         ` Hans Hagen
2012-05-06 13:39       ` Mari Voipio
     [not found]         ` <4FA6822A.6070400@wxs.nl>
2012-05-08  5:53           ` Mari Voipio
2012-04-30 21:40 ` Mari Voipio
2012-05-01 17:09   ` Peter Rolf [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=4FA018BA.6000707@gmx.net \
    --to=indiego@gmx.net \
    --cc=mari.voipio@iki.fi \
    --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).