From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/75811 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: Metapost/Metafun Q: using variables and "building blocks"? Date: Mon, 23 Apr 2012 20:04:44 +0200 Message-ID: <4F9599BC.2000301@wxs.nl> 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"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1335204322 3623 80.91.229.3 (23 Apr 2012 18:05:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 Apr 2012 18:05:22 +0000 (UTC) Cc: Mari Voipio To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Apr 23 20:05:21 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 1SMNdY-0003Mk-Mn for gctc-ntg-context-518@m.gmane.org; Mon, 23 Apr 2012 20:05:20 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 69AD2101CF; Mon, 23 Apr 2012 20:05: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 PkCxD2I7AtpU; Mon, 23 Apr 2012 20:05:17 +0200 (CEST) Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B4CCB101DF; Mon, 23 Apr 2012 20:05:17 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id F3214101DF for ; Mon, 23 Apr 2012 20:05:15 +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 dUs3hzCeCh3V for ; Mon, 23 Apr 2012 20:05:15 +0200 (CEST) Original-Received: from filter1-nij.mf.surf.net (filter1-nij.mf.surf.net [195.169.124.152]) by balder.ntg.nl (Postfix) with ESMTP id 18AC4101CF for ; Mon, 23 Apr 2012 20:05:15 +0200 (CEST) Original-Received: from smtp.ziggozakelijk.nl (D57D1DA2.static.ziggozakelijk.nl [213.125.29.162]) by filter1-nij.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q3NI5DBZ006482 for ; Mon, 23 Apr 2012 20:05:13 +0200 X-Default-Received-SPF: pass (skip=loggedin (res=PASS)) x-ip-name=10.100.1.100; Original-Received: from [10.100.1.100] (unverified [10.100.1.100]) by pragma-net.nl (SurgeMail 5.3h2) with ESMTP (TLS) id 113-1713362 for multiple; Mon, 23 Apr 2012 20:05:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 In-Reply-To: X-Authenticated-User: hagen@controller-9 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=213.125.29.162; country=NL; region=03; city=Hattem; latitude=52.4724; longitude=6.0696; http://maps.google.com/maps?q=52.4724,6.0696&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 07H1u5d1w - d3123d593973 - 20120423 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 195.169.124.152 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:75811 Archived-At: On 23-4-2012 19:34, Mari Voipio wrote: > Hello all, > > any graphic experts around who can bump me past a stupid hinder on my > way to understanding MPgraphics? > > > I'm trying to create a system of describing certain type of braiding > patterns (fingerloop braiding), based on what has been used in the > field before me - but they did it all manually either by pen or > computer, and I just do not fancy doing 40+ patterns by hand in > Inkscape, especially as my pattern recipe book keeps expanding and I'm > planning on that, too. > > I think Metapost could be the solution, because I need simple shapes > and sometimes complicated but well-regulated paths/arrows to go > between them; I'm just being a clueless newbie, too much in the > WYSIWYG vector graphics mode to really know what to do. > > > Mostly with the examples in the Metafun manual I've managed to get as > far as to my basic building block, two circles joined by a curve: > > > \startMPpage > path p, q, r ; > > p := fullcircle scaled 8mm ; > q := p shifted (0cm,24mm) ; > r := center p .. (12mm,12mm) .. 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 ; > draw p withpen pencircle scaled 0.2mm withcolor black ; fill p withcolor white; > draw q withpen pencircle scaled 0.2mm withcolor black ; fill q withcolor black; > \stopMPpage > > > > However, I don't seem to be able to find the answers to the next questions: > > a) I need to be able to stack four of these on top of each other and > then four mirrored ones next to them (all-in-all a 2 x 4 grid/block), > and probably a 1-block space between the two columns. I realize I can > do that with "shift", but should I make my single 'building block' a > group, a buffer or overlay or something else? 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. > (At some point I need to expand to more columns, but the number of > rows is still 4 as we have humans have just four aligned fingers per > hand - thumbs aren't counted - but one can add hands i.e. people to > work wider braids.) > > > 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 (e.g. two totally black, two totally white, two > half-and-half with either black or white on top). The pen/outline > colour should stay as black, which means that I can't implement the > symbol example in the Metafun manual (the smiley that is totally > switched from black to red). > I don't mind having different blocks for monocoloured and bicoloured > versions, but it would be nice to be able to say something like > \usesloop[lh,blue] for 'take a single-coloured left-hand loop in blue' > instead of having to dig deeper into the MP code every time. > > I assume the answer is "use variables", but how? something: \startMPpage def MyShape = image ( path p, q, r ; p := fullcircle scaled 8mm ; q := p shifted (0cm,24mm) ; r := center p .. (12mm,12mm) .. 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 ; draw p withpen pencircle scaled 0.2mm withcolor black ; fill p withcolor white; draw q withpen pencircle scaled 0.2mm withcolor black ; fill q withcolor black; ) enddef ; for i=0 step 2cm until 8cm : for j=0 step 4cm until 12cm : draw MyShape shifted (i,j) ; endfor ; endfor ; \stopMPpage there are picture variables, so picture pp ; pp := image(...) ; can be used > I used millimeters here because it just feels more natural to me, > that's what textile crafts does (when not based on inches like > quilting and scrapbooking...). The measurements won't be shown > anywhere - these are graphs or pictograms, not real pictures - so I > can still switch to using something else. Besides, if the "building > block" approach works, there isn't that much to be changed, get the > first block right and the rest can be calculated from there. mm are okay, alternative use no dimension, just numbers and scale afterwards: currentpicture := currentpicture xsized 10cm ; or so. > PS. Today's craft related metaphor: I feel just like I was staring at > a messed up skein of yarn: I know that I'm now holding one of the > ends, I thus can start to untangle the knot - and the more I pry > loose, the less there's left to sort out. However, in the beginning > the process tends to be very slow and awkward... beware, metapost is addictive once you get better in it, (btw, a talk about this will fit nicely in the upcoming eurotex theme) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________ 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 ___________________________________________________________________________________