From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/75918 Path: news.gmane.org!not-for-mail From: Peter Rolf Newsgroups: gmane.comp.tex.context Subject: Re: Metapost/Metafun Q: using variables and "building blocks"? Date: Tue, 01 May 2012 19:09:14 +0200 Message-ID: <4FA018BA.6000707@gmx.net> References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1335892165 25624 80.91.229.3 (1 May 2012 17:09:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 1 May 2012 17:09:25 +0000 (UTC) Cc: Mari Voipio To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue May 01 19:09:24 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SPGZo-0002fY-5v for gctc-ntg-context-518@m.gmane.org; Tue, 01 May 2012 19:09:24 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 5CB4310200; Tue, 1 May 2012 19:09:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with LMTP id yN8V8UnQnkVp; Tue, 1 May 2012 19:09:20 +0200 (CEST) Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 71F0C101EA; Tue, 1 May 2012 19:09:20 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 245E4101EA for ; Tue, 1 May 2012 19:09:19 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with LMTP id APvF6+3V2CPb for ; Tue, 1 May 2012 19:09:18 +0200 (CEST) Original-Received: from filter2-til.mf.surf.net (filter2-til.mf.surf.net [194.171.167.218]) by balder.ntg.nl (Postfix) with ESMTP id 3833B101E9 for ; Tue, 1 May 2012 19:09:18 +0200 (CEST) Original-Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23]) by filter2-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with SMTP id q41H9EHU009900 for ; Tue, 1 May 2012 19:09:17 +0200 Original-Received: (qmail invoked by alias); 01 May 2012 17:09:14 -0000 Original-Received: from ip-178-200-48-212.unitymediagroup.de (EHLO [192.168.178.3]) [178.200.48.212] by mail.gmx.net (mp037) with SMTP; 01 May 2012 19:09:14 +0200 X-Authenticated: #24293357 X-Provags-ID: V01U2FsdGVkX18waPQIYTswmD3iapc85ir+KTu751AKGmngrou/+E h/wqCOEjYeP0Yt User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120420 Thunderbird/12.0 In-Reply-To: X-Enigmail-Version: 1.4.1 X-Y-GMX-Trusted: 0 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=213.165.64.23; country=DE; latitude=51.0000; longitude=9.0000; http://maps.google.com/maps?q=51.0000,9.0000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0TH4F9e9d - a716a2d3994b - 20120501 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.218 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:75918 Archived-At: Hi Mari, Am 30.04.2012 23:40, schrieb Mari Voipio: > On Mon, Apr 23, 2012 at 20:34, Mari Voipio 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 ___________________________________________________________________________________