Metapost/Metafun Q: using variables and "building blocks"?
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? 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. Any ideas on how I can achieve the ease that surely exists somewhere there? I'll take plain Metapost or a combination of Metapost and Metafun + ConTeXt as I'll use ConTeXt anyway to achieve multi-format output with a minimum of fuss. Help thankfully received, as always, Mari 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...
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 -----------------------------------------------------------------
On Mon, Apr 23, 2012 at 9:04 PM, Hans Hagen
beware, metapost is addictive once you get better in it,
It is. :-) This one is to both you and Peter, because your snippets together helped me adjust from WYSIWYG vector graphics to MetaPost - not that I'm that far yet, but I understand a lot more than I did. http://www.lucet.fi/textiles/ The fingerloop braiding patterns are still under construction, but I think I now know a lot better what I need to do there. And my fingerloop braiding suite idea was well received, so it looks like ConTeXt will be present at Braids 2012 in August (http://www.braidsociety.com/confer.htm); not as a talk, but as finished materials, in poster form and, obviously, on my computer.
(btw, a talk about this will fit nicely in the upcoming eurotex theme)
I think I already happened to promise that to Taco... I guess the title of my talk is now "TeXtile craft" or "TeXtiles" or something like that. You still time to make a wish or two. :-) Definitely hooked on MetaPost, Mari
PS. I got this link from a friend who'd struggled with an event registration system, but it SO applies to my MetaPost project: http://www.howtogeek.com/102420/geeks-versus-non-geeks-when-doing-repetitive... (Scary, I seem to count as "geek"now...)
On Sun, May 6, 2012 at 10:53 AM, Mari Voipio
http://www.lucet.fi/textiles/ """ ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is not open source software, """ Hm, I'm not sure that it's correct. -- luigi
Am 06.05.2012 um 11:16 schrieb luigi scarso:
On Sun, May 6, 2012 at 10:53 AM, Mari Voipio
wrote: http://www.lucet.fi/textiles/ """ ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is not open source software, """ Hm, I'm not sure that it's correct.
ConTeXt is licensed under the GPL, you can find the information in this document: http://pragma-ade.com/general/manuals/mreadme.pdf Wolfgang
On Sun, May 6, 2012 at 11:56 AM, Wolfgang Schuster
Am 06.05.2012 um 11:16 schrieb luigi scarso:
On Sun, May 6, 2012 at 10:53 AM, Mari Voipio
wrote: http://www.lucet.fi/textiles/ """ ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is not open source software, """ Hm, I'm not sure that it's correct.
ConTeXt is licensed under the GPL, you can find the information in this document: http://pragma-ade.com/general/manuals/mreadme.pdf
yes I know: another useful link is http://en.wikipedia.org/wiki/Talk:ConTeXt I think we can say that, at least today, "ConTeXt is not open source software" is wrong, but maybe there are older versions for which this statement is still true. -- luigi
On Sun 06 May 2012, Wolfgang Schuster wrote:
Am 06.05.2012 um 11:16 schrieb luigi scarso:
On Sun, May 6, 2012 at 10:53 AM, Mari Voipio
wrote: http://www.lucet.fi/textiles/ """ ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is not open source software, """ Hm, I'm not sure that it's correct.
ConTeXt is licensed under the GPL, you can find the information in this document: http://pragma-ade.com/general/manuals/mreadme.pdf
There was previous discussion and clarification on this at http://tex.stackexchange.com/questions/12431/using-context-commercially and http://archive.contextgarden.net/message/20110301.213750.c7a55835.en.html . Pont
On 6-5-2012 13:33, Pontus Lurcock wrote:
On Sun 06 May 2012, Wolfgang Schuster wrote:
Am 06.05.2012 um 11:16 schrieb luigi scarso:
On Sun, May 6, 2012 at 10:53 AM, Mari Voipio
wrote: http://www.lucet.fi/textiles/ """ ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is not open source software, """ Hm, I'm not sure that it's correct.
ConTeXt is licensed under the GPL, you can find the information in this document: http://pragma-ade.com/general/manuals/mreadme.pdf
There was previous discussion and clarification on this at http://tex.stackexchange.com/questions/12431/using-context-commercially and http://archive.contextgarden.net/message/20110301.213750.c7a55835.en.html .
In the past (previous century, first releases) there hqad been some restrictions (i've forgotten which) that had to do with the fact that a third party was using context for a project and that we got notice that lawyers of that company would claimed copyright of context because it had become part of their workflow ... so, we had to make sure that by making context public it could not be used against us (like: we take context, add a few lines, and now it's ours). Then someone convinced us that people who 'd do such things would probably get themselves outcast from any community anyway, i.e. that there is some protection is being part of the tex community. I think that there are still some recomendations with respect to not using the same filenames for patched files (simply because tex is always a large file infrastructure and we don't want to be bothered with support for such patched). AFAIK that is not much different than with latex. Anyhow, license discussions are mostly wasted on me. 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 -----------------------------------------------------------------
On 6-5-2012 10:53, Mari Voipio wrote:
On Mon, Apr 23, 2012 at 9:04 PM, Hans Hagen
wrote: beware, metapost is addictive once you get better in it,
It is. :-)
This one is to both you and Peter, because your snippets together helped me adjust from WYSIWYG vector graphics to MetaPost - not that I'm that far yet, but I understand a lot more than I did.
Best change that in: ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is open source software and avaliable as stand alone distribution (www.contextgarden.net) and is also part of regular tex distributions (like texlive). It can be used commercially (within the rules of gpl etc etc) which I'm sure of some folks do. Of course you could joke that 'commercial usage is permitted given that a donation is made to the context group so that those involved can meet every now and then to discuss its usage and present recent work like yours). (btw, I always wonder if the gpl restrictions also apply to the makers too ... i.e. if I extend context for a project should I then also make those extensions public ... quite a hassle if that would be true.) 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 -----------------------------------------------------------------
2012/5/6 Hans Hagen
(btw, I always wonder if the gpl restrictions also apply to the makers too ... i.e. if I extend context for a project should I then also make those extensions public ... quite a hassle if that would be true.)
The copyright holders are free to use any license. So we have the "free" ConTeXt used by anybody but Pragma and the "non-free" version sold by Pragma to its customers. https://en.wikipedia.org/wiki/Dual_license Best Martin
On 6-5-2012 14:53, Martin Schröder wrote:
2012/5/6 Hans Hagen
: (btw, I always wonder if the gpl restrictions also apply to the makers too ... i.e. if I extend context for a project should I then also make those extensions public ... quite a hassle if that would be true.)
The copyright holders are free to use any license. So we have the "free" ConTeXt used by anybody but Pragma and the "non-free" version sold by Pragma to its customers.
Ok. Not that we ever sold something (if needed we install it as part of a service). Of course we do make non public styles but I suppose that a 'free' context user can do that as well. 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 -----------------------------------------------------------------
On Sun, May 6, 2012 at 3:47 PM, Hans Hagen
Best change that in:
ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is open source software and avaliable as stand alone distribution (www.contextgarden.net) and is also part of regular tex distributions (like texlive).
OK, done. And I added some more stuff that I forgot originally. Don't know if I should split the page into smaller units - but somehow I feel that those who'll be interested in it, are capable of reading more than one screenful. We'll see what this turns into. Today I used my new skills with frames and the Lucida OT Handwriting to create insides for a Mother's Day card as I needed something that is exactly the right size. :-D Thank you, Mari
On Mon, Apr 23, 2012 at 20:34, Mari Voipio
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... Getting closer, Mari PS. I don't have any photos of the above braid, but here's a typical fingerloop braid that I did and need to document: http://www.lucet.fi/2012/04/sydamellista-hearty/
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
participants (7)
-
Hans Hagen
-
luigi scarso
-
Mari Voipio
-
Martin Schröder
-
Peter Rolf
-
Pontus Lurcock
-
Wolfgang Schuster