Re: [NTG-context] Fuzzy lines

2021-09-03 Thread Henning Hraban Ramm via ntg-context

> 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




sketchtest2.pdf
Description: Adobe PDF document


mp-sketch.mp
Description: Binary data
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-14 Thread Henning Hraban Ramm

> 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:
> 
> https://github.com/jemmybutton/fiziko

Just WOW

HR
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-14 Thread Thomas A. Schmitz

> 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
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-14 Thread Hans Hagen

On 5/13/2021 6:36 PM, Aditya Mahajan wrote:

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 
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
-
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-14 Thread Hans Hagen

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
-
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Aditya Mahajan
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___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Henning Hraban Ramm


> 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




mp-sketch.mp
Description: Binary data


sketchtest.mp
Description: Binary data


covertest.tex
Description: Binary data
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread 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...


Thomas

\setupbodyfont[20pt]

\showframe

\startuseMPgraphic{fuzzy}

path p ; p := (0,0) -- (0,OverlayHeight) -- (OverlayWidth,OverlayHeight) --
(OverlayWidth,0) -- cycle ;

pickup pencircle scaled .5pt ;

for i=1 upto 20 :
 draw p enlarged -5pt randomized 15pt withcolor blue ;
endfor ;

\stopuseMPgraphic

\defineoverlay [Fuzzy] [\useMPgraphic{fuzzy}]

\startTEXpage


\framed [height=20cm,width=12cm,frame=on,background=Fuzzy,align={middle,lohi}]
{Test}

\stopTEXpage

test.pdf
Description: Adobe PDF document
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Henning Hraban Ramm


> 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




sketchtest.mp
Description: Binary data
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread 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. 

Aditya%D \module
%D   [   file=mp-sketch.mp
%Dversion=2021.05.13
%D  title=\CONTEXT\ \METAPOST\ graphics,
%D   subtitle=Sketch drawing,
%D author=Aditya Mahajan,
%D   date=\currentdate,
%D  copyright={Aditya Mahajan}]

%D This metapost module is inspired by a TeX.SE question:
%D http://tex.stackexchange.com/q/39296/323
%D
%D I thought that it would be fun to implement a similar feature in MetaPost.
%D
%D To use this package in MetaPost:
%D
%D \starttyping
%Dinput mp-sketch;
%D
%Dbeginfig(1)
%D  sketchypaths; % Make draw and fill sketchy
%D  ...
%D  naturalizepaths; % Restore the value of draw and fill
%D  ...
%Dendfig
%D \stoptyping
%D
%D The code is heavily inspired by Hans Hagen's Metafun macros.
%D
%D The macro \type{sketchypaths} is modeled after \type{visualizepaths} from
%D \filename{mp-tool}.

def sketchypaths =
let draw = sketchdraw ;
let fill = sketchfill ;
enddef ;

%D Check if \filename{mp-tool} is loaded
if not known context_tool :
  let normaldraw = draw;
  let normalfill = fill;

  def naturalizepaths =
  let fill = normalfill ;
  let draw = normaldraw ;
  enddef ;
fi

%D The variable \type{sketch_amount} determines the amount of randomness in the
%D drawing
numeric sketch_amount; sketch_amount := 0.75bp;

%D The variable \type{sketch_passes} determines the number of times the path
%D is drawn
numeric sketch_passes; sketch_passes := 1;

%D Based on \type{randomized}. Assumes p is path:
numeric sketch_segments; sketch_segments := 20;

primarydef p sketchrandomized s = (
if path p :
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
if cycle p :
cycle
else :
((point arclength(p) on p) randomshifted s)
fi
else :
p
fi
) enddef ;


%D The macro \type{sketchdraw} draws the randomized path. The 
%D \type{expr} ... \type{text} trick is copied from the definition of 
%D \type{drawarrow}
def sketchdraw expr p =
   do_sketchdraw(p)
enddef;

def do_sketchdraw(expr p) text t =
  if (path p) :
  for i = 1 upto max(1,sketch_passes) :
normaldraw p 
   sketchrandomized sketch_amount 
   withtransparency ("multiply", 1/max(1,sketch_passes))
   t ;
  endfor;
  else :
  normaldraw p t;
  fi
enddef;

%D The macro \type{sketchfill} randomizes the path before filling it.
def sketchfill expr p =
  do_sketchfill(p)
enddef ;

def do_sketchfill(expr p) text t =
  if (path p) :
  for i = 1 upto max(1,sketch_passes) :
normalfill p 
   randomized sketch_amount 
   withtransparency ("multiply", 1/max(1,sketch_passes))
   t ;
  endfor;
  else :
  normalfill p t;
  fi
enddef;

endinput;

% Modified example from
% http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html

beginfig(1)
  pair A,B,C,O;
  A=(0,0); B=(3cm,0); C=(1cm,2cm);

  O - 1/2[B,C] = whatever * (B-C) rotated 90;
  O - 1/2[A,B] = whatever * (A-B) rotated 90;

  sketchypaths;
  sketch_amount := 5bp;
  draw A--B--C--cycle;

  draw O withpen pencircle scaled 4bp;

  sketch_amount := 2bp;
  draw fullcircle scaled 2abs(O-A) shifted O;
endfig


test.tex
Description: TeX document


test.pdf
Description: Adobe PDF document
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Henning Hraban Ramm

> 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

___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Aditya Mahajan
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;

test.pdf
Description: Adobe PDF document


test.tex
Description: TeX document
%D \module
%D   [   file=mp-sketch.mp
%Dversion=2021.05.13
%D  title=\CONTEXT\ \METAPOST\ graphics,
%D   subtitle=Sketch drawing,
%D author=Aditya Mahajan,
%D   date=\currentdate,
%D  copyright={Aditya Mahajan}]

%D This metapost module is inspired by a TeX.SE question:
%D http://tex.stackexchange.com/q/39296/323
%D
%D I thought that it would be fun to implement a similar feature in MetaPost.
%D
%D To use this package in MetaPost:
%D
%D \starttyping
%Dinput mp-sketch;
%D
%Dbeginfig(1)
%D  sketchypaths; % Make draw and fill sketchy
%D  ...
%D  naturalizepaths; % Restore the value of draw and fill
%D  ...
%Dendfig
%D \stoptyping
%D
%D The code is heavily inspired by Hans Hagen's Metafun macros.
%D
%D The macro \type{sketchypaths} is modeled after \type{visualizepaths} from
%D \filename{mp-tool}.

def sketchypaths =
let draw = sketchdraw ;
let fill = sketchfill ;
enddef ;

%D Check if \filename{mp-tool} is loaded
if not known context_tool :
  let normaldraw = draw;
  let normalfill = fill;

  def naturalizepaths =
  let fill = normalfill ;
  let draw = normaldraw ;
  enddef ;
fi

%D The variable \type{sketch_amount} determines the amount of randomness in the
%D drawing
numeric sketch_amount; sketch_amount := 3bp;

%D The variable \type{sketch_passes} determines the number of times the path
%D is drawn
numeric sketch_passes; sketch_passes := 1;

%D The macro \type{sketchdraw} draws the randomized path. The 
%D \type{expr} ... \type{text} trick is copied from the definition of 
%D \type{drawarrow}
def sketchdraw expr p =
   do_sketchdraw(p)
enddef;

def do_sketchdraw(expr p) text t =
  if (path p) :
  for i = 1 upto max(1,sketch_passes) :
normaldraw p 
   randomized sketch_amount 
   withtransparency ("multiply", 1/max(1,sketch_passes))
   t ;
  endfor;
  else :
  normaldraw p t;
  fi
enddef;

%D The macro \type{sketchfill} randomizes the path before filling it.
def sketchfill expr p =
  do_sketchfill(p)
enddef ;

def do_sketchfill(expr p) text t =
  if (path p) :
  for i = 1 upto max(1,sketch_passes) :
normalfill p 
   randomized sketch_amount 
   withtransparency ("multiply", 1/max(1,sketch_passes))
   t ;
  endfor;
  else :
  normalfill p t;
  fi
enddef;

endinput;

% Modified example from
% http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html

beginfig(1)
  pair A,B,C,O;
  A=(0,0); B=(3cm,0); C=(1cm,2cm);

  O - 1/2[B,C] = whatever * (B-C) rotated 90;
  O - 1/2[A,B] = whatever * (A-B) rotated 90;

  sketchypaths;
  sketch_amount := 5bp;
  draw A--B--C--cycle;

  draw O withpen pencircle scaled 4bp;

  sketch_amount := 2bp;
  draw fullcircle scaled 2abs(O-A) shifted O;
endfig
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Henning Hraban Ramm

> Am 12.05.2021 um 23:21 schrieb Jairo A. del Rio :
>> Unfortunately, that’s the same pattern over and over.
>> The randomization is only applied once.
>> Good for footprints, bad for fuzzy patterns.
>> 
> You only need to move "randomized" at the drawing stage:
> 
> \starttext
> \startMPpage
> numeric u; u := 1mm;
> picture Pluma;
> Pluma := image(
>   for i = 1 upto 5:
>   for j = 1 upto 5:
>   draw (i,j);
>   endfor
>   endfor
> );

I made it into:

  picture NoisePattern;
  NoisePattern := image(
pickup pencircle xyscaled 0.5bp;
numeric pmax ; pmax := 7 ;
for i = 1 upto pmax:
for j = 1 upto pmax:
draw (i - (pmax/2), j - (pmax/2)) 
withcolor LineColor 
withtransparency ("normal", (uniformdeviate 0.33));
endfor
endfor
  );

Now the noise is randomly transparent and also on (and not over) the path.


> path Camino;
> Camino := origin for i = 1 upto 30: .. (u*i, u*sind (12i mod 360)) endfor;
> for i = 0 step 1/2 until length Camino:
>   draw Pluma randomized 1 rotated (90 + angle direction i of Camino)
>   shifted point i of Camino;
> endfor

And that became:

  def noisify(expr p) =
for i = 0 step 0.01 until length p:
draw NoisePattern randomized 1 shifted point i of p ;
endfor
  enddef;

I still need to account for the length of the path in the loop step.


> But "randomized" will deform paths. Maybe you want something like this?
> 
> \starttext
> \startMPpage[align=]
> begingroup;
> save Rnd; let Rnd = uniformdeviate;
> 
> numeric u; u := 3mm;
> picture Pluma;
> Pluma := image(
>   for i = 1 upto 5:
>   for j = 1 upto 5:
>   fill fullcircle shifted (i,j); %try fulltriangle or 
> another shape
>   endfor
>   endfor
> );
> path Camino;
> Camino := origin for i = 1 upto 30: .. u*i*left endfor;
> for i = 0 step 1/2 until length Camino:
>   draw image(
>   for x within Pluma:
>   fill pathpart x %Assuming our image only contains cyclic paths
>   scaled (1+Rnd 1)
>   shifted (1/2dir Rnd 360)
>   withcolor hsvtorgb(6round(Rnd 60),9/10,1); %Colors just because 
> they look cute
>   endfor
>   ) rotated (90 + angle direction i of Camino)
>   shifted point i of Camino;
> endfor
> endgroup;
> \stopMPpage
> \stoptext

>> 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.
> You only need to use fractions, i.e., "for 0 step 1/n until 1: ... endfor" if 
> you work with straight lines defined using only two points.

Yes, I got that. But a fixed number (e.g. step 0.01 like above) doesn’t account 
for paths of different length.
I guess I’d need an algorithm like for dashed lines to get uniform noise on 
paths of different length.
(I also looked at dashpattern in the MP manual, but they’re not usable for 
patterns like this.)

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
___


Re: [NTG-context] Fuzzy lines

2021-05-13 Thread Henning Hraban Ramm

> 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
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-12 Thread Henning Hraban Ramm
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
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-12 Thread Henning Hraban Ramm
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

___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-11 Thread Aditya Mahajan


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

___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-11 Thread Henning Hraban Ramm
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

___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-11 Thread Jairo A. del Rio
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 (mic...@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
>
> ___
>


163.pdf
Description: Adobe PDF document
___
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
___


Re: [NTG-context] Fuzzy lines

2021-05-11 Thread Mikael Sundqvist
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
___


[NTG-context] Fuzzy lines

2021-05-11 Thread 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
___