Hi MetaFans, is it possible to get lines with Metapost that look like they were drawn with a pencil or brush? Some vector graphics apps (in my case: Affinity Designer) can use such naturally looking brushes for vector graphics (and I don’t know how they do it), but I’d like to automate/parametrize some designs, and that would finally be a reason to learn Metapost... Hraban
Hi!
Not really what you ask for, perhaps, but this could be interesting
for you: https://tex.stackexchange.com/q/39296/52406
/Mikael
On Tue, May 11, 2021 at 12:58 PM Henning Hraban Ramm
Hi MetaFans,
is it possible to get lines with Metapost that look like they were drawn with a pencil or brush?
Some vector graphics apps (in my case: Affinity Designer) can use such naturally looking brushes for vector graphics (and I don’t know how they do it), but I’d like to automate/parametrize some designs, and that would finally be a reason to learn Metapost...
Hraban ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Hi Mikael, thank you, there are some interesting ideas. We have already seen a lot of randomization in paths; duplicating a randomized path with varying saturation enhances the effect. With PGF/TikZ I could maybe use a brush decoration on a path. Is it possible to use a irregular "pen" in MetaPost? With transparency? The MF manual says in 1.11, pens are limited, but not how. Or are properties (MF manual 8.10) the way to go? Hraban
Am 11.05.2021 um 13:30 schrieb Mikael Sundqvist
: Not really what you ask for, perhaps, but this could be interesting for you: https://tex.stackexchange.com/q/39296/52406
/Mikael
On Tue, May 11, 2021 at 12:58 PM Henning Hraban Ramm
wrote: is it possible to get lines with Metapost that look like they were drawn with a pencil or brush?
Some vector graphics apps (in my case: Affinity Designer) can use such naturally looking brushes for vector graphics (and I don’t know how they do it), but I’d like to automate/parametrize some designs, and that would finally be a reason to learn Metapost...
Hraban
For simple pens, you may define your own (section 9.7 of MetaPost manual). For complicated strokes, something along these lines could be useful as a starting point (I'm not taking cyclic paths in consideration, btw). I did something similar with duck footprints some weeks ago: %Sorry for the ugly code... \starttext \startMPpage %Unit size numeric u; u := 1mm; %In a picture you are able to include everything, kinda picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: draw (i,j) randomized 1; endfor endfor ); %Simple curve path Camino; Camino := origin for i = 1 upto 30: .. (u*i, u*sind (12i mod 360)) endfor; %Strokes for i = 0 step 1/2 until length Camino: draw Pluma rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor \stopMPpage \stoptext Not sure if that's what you need... Regards, Jairo El mar, 11 de may. de 2021 a la(s) 06:31, Mikael Sundqvist (mickep@gmail.com) escribió:
Hi!
Not really what you ask for, perhaps, but this could be interesting for you: https://tex.stackexchange.com/q/39296/52406
/Mikael
On Tue, May 11, 2021 at 12:58 PM Henning Hraban Ramm
wrote: Hi MetaFans,
is it possible to get lines with Metapost that look like they were drawn
with a pencil or brush?
Some vector graphics apps (in my case: Affinity Designer) can use such
naturally looking brushes for vector graphics (and I don’t know how they do it), but I’d like to automate/parametrize some designs, and that would finally be a reason to learn Metapost...
Hraban
___________________________________________________________________________________
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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net
___________________________________________________________________________________
___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net
___________________________________________________________________________________
On Tue, 11 May 2021, Jairo A. del Rio wrote:
For simple pens, you may define your own (section 9.7 of MetaPost manual). For complicated strokes, something along these lines could be useful as a starting point (I'm not taking cyclic paths in consideration, btw). I did something similar with duck footprints some weeks ago:
%Sorry for the ugly code...
Look at this old code on how hide such code behind a macro to have a clean interface: https://github.com/adityam/mp-sketch/blob/master/mp-sketch.mp Sometimes I use such effects in presentations but you have to resist the temptation to overdo it: http://www.cim.mcgill.ca/~adityam/talks/2016-it-forum.pdf Aditya
Hi Aditya, thanks for the code (that also Mikael pointed to)!
Am 11.05.2021 um 18:02 schrieb Aditya Mahajan
: Look at this old code on how hide such code behind a macro to have a clean interface:
https://github.com/adityam/mp-sketch/blob/master/mp-sketch.mp
I came up with this simple cover layout: input mp-sketch; beginfig(1) color darkblue ; darkblue := (40/255,67/255,117/255) ; pen pillpen ; pillpen := makepen ((-1bp,-0.5bp)--(1bp,-0.5bp)..(1bp,0.5bp)--(-1bp,0.5bp)..cycle) ; pickup pillpen xyscaled 3bp ; sketchypaths; sketch_amount := 5bp; % insert some extra points to add fuzzyness - automate? % path one ; one := (-3mm,249mm) -- (185mm,249mm) -- (185mm,300mm) ; % links-oben path onep ; onep := (-3mm,249mm) .. (25.5mm,249mm) .. (150mm,249mm) -- (185mm,249mm) -- (185mm,300mm) ; % links-oben % path two ; two := (25.5mm,-3mm) -- (25.5mm,167mm) -- (213mm,167mm) ; % unten-rechts path twop ; twop := (25.5mm,-3mm) .. (25.5mm,25.5mm) .. (25.5mm,120mm) -- (25.5mm,167mm) .. (120mm,167mm) -- (213mm,167mm) ; % unten-rechts % draw paths several times - automate? numeric max ; max := 5; for i=0 upto max : draw onep withcolor darkblue withtransparency ("multiply", 1/max) ; draw twop withcolor darkblue withtransparency ("multiply", 1/max) ; endfor naturalizepaths; % draw crop box (paper size) pickup pencircle xyscaled 0.5bp; draw (0,0)--(0,297mm)--(210mm,297mm)--(210mm,0)--cycle withcolor magenta; endfig This begins to look like I imagined, even if I’d like to add some noise (pattern, shading). Jairo’s suggestion looks too regular. (Finally, I’ll overlay the whole page with a transparent image for structure.) As you see, both paths use only three points, but I added some more to add fuzzyness. Also they get drawn several times with transparency to get a irregular width and some blur. I’m quite sure this could be added to your macro, but I’m still too inexperienced with Metapost. Hraban
Am 11.05.2021 um 18:02 schrieb Aditya Mahajan
: Look at this old code on how hide such code behind a macro to have a clean interface:
https://github.com/adityam/mp-sketch/blob/master/mp-sketch.mp
Hi Aditya, I’m trying to include my additions into your code, but it doesn’t work. numeric sketch_amount; sketch_amount := 3bp; numeric sketch_passes; sketch_passes := 5; def sketchdraw expr p = do_sketchdraw(p if (path p): randomized sketch_amount fi) enddef; def do_sketchdraw(expr p) text t = normaldraw p t ; enddef; Now I want to draw that path several times. If I understand it right, I can’t put that into "sketchdraw" because that leaves the end open for path additions like "withcolor". But it also doesn’t work in "do_sketchdraw"; I thought it might like this: def do_sketchdraw(expr p) text t = for i=0 upto sketch_passes : normaldraw p t ; % withtransparency ("multiply", 1/sketch_passes) ; % and how can I add that without breaking other additions? endfor enddef; But that just blocks, I guess there’s an infinite loop. I’d be happy about some advise. Hraban
On Thu, 13 May 2021, Henning Hraban Ramm wrote:
Am 11.05.2021 um 18:02 schrieb Aditya Mahajan
: Look at this old code on how hide such code behind a macro to have a clean interface:
https://github.com/adityam/mp-sketch/blob/master/mp-sketch.mp
Hi Aditya, I’m trying to include my additions into your code, but it doesn’t work.
numeric sketch_amount; sketch_amount := 3bp; numeric sketch_passes; sketch_passes := 5;
def sketchdraw expr p = do_sketchdraw(p if (path p): randomized sketch_amount fi) enddef;
def do_sketchdraw(expr p) text t = normaldraw p t ; enddef;
Now I want to draw that path several times.
If I understand it right, I can’t put that into "sketchdraw" because that leaves the end open for path additions like "withcolor".
But it also doesn’t work in "do_sketchdraw"; I thought it might like this:
A slightly different approach is needed. See attached. I also added a bit a error protection in case someone sets sketch_passes to be negative by mistake. It may be interesting to rewrite these macros using the new key-value interface for metapost, so that something like this works: \sketchdraw[amount=3bp, passes=5, transparency=yes] fullsquare scaled 1cm withcolor red;
Am 13.05.2021 um 18:36 schrieb Aditya Mahajan
: Now I want to draw that path several times.
If I understand it right, I can’t put that into "sketchdraw" because that leaves the end open for path additions like "withcolor".
A slightly different approach is needed. See attached. I also added a bit a error protection in case someone sets sketch_passes to be negative by mistake.
Thank you so much!
It may be interesting to rewrite these macros using the new key-value interface for metapost, so that something like this works:
\sketchdraw[amount=3bp, passes=5, transparency=yes] fullsquare scaled 1cm withcolor red;
Yes, I just read the luametafun manual and will try a few things – but this is still over my head. Hraban
On Thu, 13 May 2021, Henning Hraban Ramm wrote:
Am 13.05.2021 um 18:36 schrieb Aditya Mahajan
: Now I want to draw that path several times.
If I understand it right, I can’t put that into "sketchdraw" because that leaves the end open for path additions like "withcolor".
A slightly different approach is needed. See attached. I also added a bit a error protection in case someone sets sketch_passes to be negative by mistake.
Thank you so much!
Here is a different effect ... more of a trembling hand drawing than a sketch. You can play around with sketch_amount to see some variation. In this, rather than using the default randomized path (which randomizes the points of a path), I split the path into 20 segments, and randomize each segment. Aditya
Am 13.05.2021 um 19:17 schrieb Aditya Mahajan
: On Thu, 13 May 2021, Henning Hraban Ramm wrote:
Am 13.05.2021 um 18:36 schrieb Aditya Mahajan
: Now I want to draw that path several times.
If I understand it right, I can’t put that into "sketchdraw" because that leaves the end open for path additions like "withcolor".
A slightly different approach is needed. See attached. I also added a bit a error protection in case someone sets sketch_passes to be negative by mistake.
Thank you so much!
Here is a different effect ... more of a trembling hand drawing than a sketch. You can play around with sketch_amount to see some variation.
In this, rather than using the default randomized path (which randomizes the points of a path), I split the path into 20 segments, and randomize each segment.
Thank you, that is what I was asking for! Unfortunately, the deviation of edge points is too big – try my attached test file. Strangely, if I include the MP code in a ConTeXt document, the transparency doesn’t work (it multiplies, but at 100%); I must add "withtransparency ("multiply", 0.2)" to my draw command. I’ll try to come up with a MWE. (Transparency of an image also doesn’t work in that document.) My test file also includes the noise overlay after Jairo’s suggestions. Maybe you want to implement that, too? At the moment it still doesn’t respect the pen size, and the number of patterns per path is fixed. Hraban
On 5/13/21 8:02 PM, Henning Hraban Ramm wrote:
Unfortunately, the deviation of edge points is too big – try my attached test file.
Strangely, if I include the MP code in a ConTeXt document,
I find the discussion interesting. Could you send complete documents, like Aditya did? When I try to compile your files, I get all sorts of errors, so I suspect they are not complete. Would be appreciated if you could send a ConTeXt document. I'm still not quite sure what you're looking for... Thomas
Am 13.05.2021 um 20:26 schrieb Thomas A. Schmitz
: On 5/13/21 8:02 PM, Henning Hraban Ramm wrote:
Unfortunately, the deviation of edge points is too big – try my attached test file. Strangely, if I include the MP code in a ConTeXt document,
I find the discussion interesting. Could you send complete documents, like Aditya did? When I try to compile your files, I get all sorts of errors, so I suspect they are not complete. Would be appreciated if you could send a ConTeXt document. I'm still not quite sure what you're looking for...
Hi Thomas, for my test files you only also need Aditya’s latest mp-sketch.mp, now attached. Find also attached my (somewhat simplified) attempt on a cover for a new workbook series. In the original I’m using the commercial "Supernett Cn" font family that also looks quite sketchy. Hraban
On 13. May 2021, at 21:42, Henning Hraban Ramm
wrote: Hi Thomas,
for my test files you only also need Aditya’s latest mp-sketch.mp, now attached.
Find also attached my (somewhat simplified) attempt on a cover for a new workbook series. In the original I’m using the commercial "Supernett Cn" font family that also looks quite sketchy.
Hraban
Perfect, thank you, that allowed me to play a bit with it. Would be interested to see what you really want to achieve one day… All best Thomas
On Thu, 13 May 2021, Henning Hraban Ramm wrote:
My test file also includes the noise overlay after Jairo’s suggestions. Maybe you want to implement that, too? At the moment it still doesn’t respect the pen size, and the number of patterns per path is fixed.
I am not sure if simply adding random noise to the line give an impression of hand-drawn lines. For a different approach, see: https://m.habr.com/en/post/454376/ which uses the code here: https://github.com/jemmybutton/fiziko Aditya
On 5/14/2021 12:39 AM, Aditya Mahajan wrote:
https://github.com/jemmybutton/fiziko That's amazing mp code, right?
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am 14.05.2021 um 00:39 schrieb Aditya Mahajan
: I am not sure if simply adding random noise to the line give an impression of hand-drawn lines. For a different approach, see:
https://m.habr.com/en/post/454376/
which uses the code here:
Just WOW HR
Am 13.05.2021 um 20:02 schrieb Henning Hraban Ramm
: Thank you, that is what I was asking for!
Unfortunately, the deviation of edge points is too big – try my attached test file.
Hi Aditya et al., coming back to this: I found "fill" was not working, since do_sketchfill didn’t use sketchrandomized. That was an easy fix. But I couldn’t fix the edge points issue: the less segments I use, the more some of the edge points deviate (see attachment with 10 segments; I used the setup from your theorems article). Lower left and upper right are good, what happens with the others? I just can’t understand the loop that splits the original path segments: for t = 0 step 1/sketch_segments until 1-1/sketch_segments : ((point (t*arclength(p)) on p) randomshifted s) .. controls ((postcontrol (t*arclength(p)) on p) randomshifted s) and ((precontrol ((t+1/sketch_segments)*arclength(p)) on p) randomshifted s) .. endfor Would it make sense to check if a point is an edge point (without curve controls)? Next question: Can I apply this to \framed and TABLE lines? (Probably only via backgrounds?) Hraban
Am 03.09.21 um 18:04 schrieb Henning Hraban Ramm via ntg-context:
Would it make sense to check if a point is an edge point (without curve controls)?
In a private reply to my old message, Hans explained to me why this was not possible like I thought (check if the point has control points), since every point has control points. But I didn’t keep at it last fall, and the MP foo is still weak in this one, so, let’s try again: If I iterate over the points of a path like in beginfig(1); path p; p = (0,0) .. (2cm,4cm) -- (4cm,5cm) .. (5cm,6cm) .. (8cm,7cm); draw p withpen pencircle scaled 2pt withcolor .7 white; for t=0 upto length p: drawdot point t of p withpen pencircle scaled 4pt withcolor red; endfor endfig; [2] How can I check if the point is an edge? (I want to randomize only the non-edge points.) 1. First or last point: if t=0 or t=length p. ... if the path is not closed: if not cycle p. OK 2. Would it make sense to check curl or tension? Can I check if the connection is specified as -- ? ?? [2] Other question on the examples from https://tex.stackexchange.com/questions/288259/how-to-draw-dots-equally-spac..., in the answer by Thruston: I want to split the path between (edge) points in segments of the same length. So disregarding the "edge" issue for now, how do I get at the path segment between points (in the for loop above) so that I can use it as a new path q in: for t=0 step s until arclength q: drawdot point arctime t of q of q withpen pencircle scaled 4pt withcolor red; endfor Hraban
On Thu, 13 May 2021, Henning Hraban Ramm wrote:
Am 11.05.2021 um 18:02 schrieb Aditya Mahajan
: Look at this old code on how hide such code behind a macro to have a clean interface:
https://github.com/adityam/mp-sketch/blob/master/mp-sketch.mp
Hi Aditya, I’m trying to include my additions into your code, but it doesn’t work.
numeric sketch_amount; sketch_amount := 3bp; numeric sketch_passes; sketch_passes := 5;
def sketchdraw expr p = do_sketchdraw(p if (path p): randomized sketch_amount fi) enddef;
def do_sketchdraw(expr p) text t = normaldraw p t ; enddef;
Now I want to draw that path several times.
If I understand it right, I can’t put that into "sketchdraw" because that leaves the end open for path additions like "withcolor".
But it also doesn’t work in "do_sketchdraw"; I thought it might like this:
A slightly different approach is needed. See attached. I also added a bit a error protection in case someone sets sketch_passes to be negative by mistake.
It may be interesting to rewrite these macros using the new key-value interface for metapost, so that something like this works:
\sketchdraw[amount=3bp, passes=5, transparency=yes] fullsquare scaled 1cm withcolor red; one resembles present-weird-001.pdf (in the doc tree) ... it was from
On 5/13/2021 6:36 PM, Aditya Mahajan wrote: the times one could rely on acrobat to jump around a large page ... i used that one for a presentation about mathml (decades ago) ... in times that the main question one got was "why use something else than latex for math" or "why use tex if you don't do math" which put context in a weird spot (but also permitted to come up with weird presentation styles that didn't look too tex) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Hi Jairo, thank you for the suggestion.
Am 11.05.2021 um 14:56 schrieb Jairo A. del Rio
: For simple pens, you may define your own (section 9.7 of MetaPost manual).
Unfortunately, pens don’t work as patterns but only as outlines.
For complicated strokes, something along these lines could be useful as a starting point (I'm not taking cyclic paths in consideration, btw). I did something similar with duck footprints some weeks ago:
%Sorry for the ugly code... \starttext \startMPpage %Unit size numeric u; u := 1mm;
%In a picture you are able to include everything, kinda picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: draw (i,j) randomized 1; endfor endfor );
Unfortunately, that’s the same pattern over and over. The randomization is only applied once. Good for footprints, bad for fuzzy patterns.
%Simple curve path Camino; Camino := origin for i = 1 upto 30: .. (u*i, u*sind (12i mod 360)) endfor;
%Strokes for i = 0 step 1/2 until length Camino: draw Pluma rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor
Since I have more or less straight lines but of different length, the "one pattern per 1/n path segment" doesn’t work for me. I could try to construct my paths differently. Hraban
participants (6)
-
Aditya Mahajan
-
Hans Hagen
-
Henning Hraban Ramm
-
Jairo A. del Rio
-
Mikael Sundqvist
-
Thomas A. Schmitz