ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henning Hraban Ramm <texml@fiee.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Fuzzy lines
Date: Thu, 13 May 2021 21:42:38 +0200	[thread overview]
Message-ID: <E4947F06-28A3-4725-B62E-2C3D6134A509@fiee.net> (raw)
In-Reply-To: <1805dfd3-a8cc-3fc6-521e-54ea0bd196c3@uni-bonn.de>

[-- Attachment #1: Type: text/plain, Size: 904 bytes --]



> Am 13.05.2021 um 20:26 schrieb Thomas A. Schmitz <thomas.schmitz@uni-bonn.de>:
> 
> 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



[-- Attachment #2: mp-sketch.mp --]
[-- Type: application/octet-stream, Size: 3816 bytes --]

%D \module
%D   [       file=mp-sketch.mp
%D        version=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
%D    input mp-sketch;
%D    
%D    beginfig(1)
%D      sketchypaths; % Make draw and fill sketchy
%D      ...
%D      naturalizepaths; % Restore the value of draw and fill
%D      ...
%D    endfig
%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

[-- Attachment #3: sketchtest.mp --]
[-- Type: application/octet-stream, Size: 2227 bytes --]

input mp-sketch;

beginfig(1)
  color darkblue ; darkblue := (40/255,67/255,117/255) ;
  color beige ; beige := (248/255,245/255,236/255) ;
  %pickup pensquare xyscaled 4bp rotated 30 ;

  % bleed box, paper shading
  fill (-3mm,-3mm)--(-3mm,300mm)--(213mm,300mm)--(213mm,-3mm)--cycle withcolor beige;

  pen pillpen ; pillpen := makepen ((-1.5bp,-0.5bp)--(1.5bp,-0.5bp)..(1.5bp,0.5bp)--(-1.5bp,0.5bp)..cycle) ;
  pickup pillpen xyscaled 3bp ;

  sketchypaths;
  sketch_amount := 5bp;
  sketch_passes := 5;
  sketch_segments := 5;

  path one ; one := (-3mm,249mm) -- (185mm,249mm) -- (185mm,300mm) ; % links-oben
  path two ; two := (25.5mm,-3mm) -- (25.5mm,130mm) -- (213mm,130mm) ; % unten-rechts

  draw one withcolor darkblue;
  draw two withcolor darkblue;

  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 darkblue withtransparency ("normal", (uniformdeviate 0.33));
  		endfor
  	endfor
  );

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

  noisify(one);
  noisify(two);

  naturalizepaths; % Restore the value of draw and fill

  % draw crop box (paper size)
  pickup pencircle xyscaled 0.5bp;
  draw (0,0)--(0,297mm)--(210mm,297mm)--(210mm,0)--cycle withcolor magenta;

  % begingroup;
  % save Rnd; let Rnd = uniformdeviate;
  %
  % numeric u; u := 3mm;
  % picture PlumaToo;
  % PlumaToo := image(
  % 	for i = 1 upto pmax:
  % 		for j = 1 upto pmax:
  %       fill fullcircle shifted (i - (pmax/2), j - (pmax/2)); %try fulltriangle or another shape
  % 		endfor
  % 	endfor
  % );
  %
  % for i = 0 step 1/20 until length one:
  % 	draw image(
  % 	for x within PlumaToo:
  % 		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
  %     withtransparency ("normal", Rnd 1);
  % 	endfor
  % 	) rotated (90 + angle direction i of one)
  % 	shifted point i of one;
  % endfor
  % endgroup;


endfig

[-- Attachment #4: covertest.tex --]
[-- Type: application/octet-stream, Size: 4990 bytes --]


\mainlanguage[de]

\setvariables[cover][
  issue={0},
  author={Autor Name},
  title={Toller Titel},
  subtitle={Aussagekräftiger Untertitel}
]

\definemeasure[Bleed][3mm]
\definemeasure[FrontOffset][210mm]

\definepapersize[Cover][% A3
  width=420mm,
  height=297mm]
\definepapersize[CoverPlus][
  width=430mm,
  height=307mm]
\setuppapersize[Cover][CoverPlus]

\definemeasure[MaxHeight][{\dimexpr\paperheight + 2\measure{Bleed}\relax}]
\definemeasure[MaxWidth][{\dimexpr\paperwidth + 2\measure{Bleed}\relax}]

\setuplayout[
  marking=on,
  location=middle,
  top=0mm,
  header=0mm,
]
\setupalign[flushleft,hanging]

\setupbodyfont[ss,24pt]

\setuppagenumbering[state=stop]

\definecolor[cmykblack][c=0,m=0,y=0,k=1]
\definecolor[LineColor][c=.9,m=.8,y=0,k=.3,t=1,a=2]
\setupcolors[
  pagecolormodel=auto,
  rgb=no,cmyk=yes,spot=no,
  state=start,
  overprint=yes,
  intent={Uncoated FOGRA29 (ISO 12647-2:2004)},
  textcolor=LineColor,
]
\setupbackend[
  format=PDF/X-4,
]
\definetransparency[tmultiply][a=2,t=1]
\definetransparency[tpaper][a=1,t=.05]

\definelayer[whole][
  width=\paperwidth,
  height=\paperheight
]

\startuniqueMPgraphic{fuzzylines}
  input mp-sketch; % by Aditya Mahajan

  pen pillpen ; pillpen := makepen ((-1.5bp,-0.5bp)--(1.5bp,-0.5bp)..(1.5bp,0.5bp)--(-1.5bp,0.5bp)..cycle) ;
  pickup pillpen xyscaled 3bp ;

  sketchypaths; % Make draw and fill sketchy
  sketch_amount := 4bp;
  sketch_passes := 5;
  sketch_segments := 10;

  path one   ; one   := (25.5mm,300mm) -- (25.5mm,249mm) -- (210mm,249mm) -- (395mm,249mm) -- (395mm,300mm) ; % links-oben
  % split horizontal and vertical parts to adapt settings:
  path one_h ; one_h := (25.5mm,249mm) -- (210mm,249mm) -- (395mm,249mm) ;
  path one_v ; one_v := (25.5mm,300mm) -- (25.5mm,249mm) ;
  path two   ; two   := (25.5mm+210mm,-3mm) -- (25.5mm+210mm,130mm) -- (213mm+210mm,130mm) ; % unten-rechts
  path three ; three := (-3mm,130mm) -- (210mm-25.5mm,130mm) -- (210mm-25.5mm,-3mm); % links-unten

  draw one withcolor "LineColor" withtransparency ("multiply", 0.2);
  draw two withcolor "LineColor" withtransparency ("multiply", 0.2);
  draw three withcolor "LineColor" withtransparency ("multiply", 0.2);

  picture NoisePattern;
  NoisePattern := image(
    pickup pencircle xyscaled 0.5bp;
    numeric pmax ; pmax := 7 ;
    numeric x ; numeric y ;
  	for i = 1 upto pmax:
  		for j = 1 upto pmax:
        % try to get more dots in the center
        x := (i - (pmax/2)) * (uniformdeviate 2.5); % we use a wide pen
        y := (j - (pmax/2)) * (uniformdeviate 1.25);
        draw (x, y) withcolor "LineColor" withtransparency ("normal", (uniformdeviate 0.33));
  		endfor
  	endfor
  );

  numeric noise_steps ; noise_steps := 100;

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

  noisify(one_h);
  noisify(two);
  noisify(three);
  noise_steps := 30;
  noisify(one_v);
  noisify(one_v shifted (369.5mm,0));

  naturalizepaths;
\stopuniqueMPgraphic

\defineoverlay[fuzzylines][\uniqueMPgraphic{fuzzylines}]

\setupbackgrounds[page][background={fuzzylines,whole},state=start]


\starttext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startlayout [page]

\definemeasure[FrontTextstart][{\dimexpr\measure{FrontOffset}+36mm\relax}]

\setlayerframed[whole][
  hoffset=-\measure{Bleed},
  voffset=-\measure{Bleed}-8mm,
  offset=overlay,
  frame=off,
  width=\measure{MaxWidth},
  height=\measure{MaxHeight},
]{\starttransparent[tpaper]% funktioniert nicht!
%\externalfigure[paper][width=\measure{MaxWidth},height=\measure{MaxHeight},rotation=90]%
\stoptransparent}

\setlayerframed[whole][
  x=\measure{FrontTextstart},
  y=60mm,
  width=150mm,
  align=flushleft,
  frame=off,
  offset=overlay,
]{\getvariable{cover}{author}}

\setlayerframed[whole][
  x=\measure{FrontTextstart}-2mm,
  y=77mm,
  height=65mm,
  width=150mm,
  align={flushleft,hanging,lohi},
  frame=off,
  offset=overlay,
]{\definedfont[SansItalic*default at 96bp]\getvariable{cover}{title}}

\setlayerframed[whole][
  x=\measure{FrontTextstart},
  y=144mm,
  width=150mm,
  align=flushleft,
  frame=off,
  offset=overlay,
]{\getvariable{cover}{subtitle}}

\setlayerframed[whole][
  x=\measure{FrontTextstart}+20mm,
  y=264.5mm,
  width=150mm,
  align=flushleft,
  frame=off,
  offset=overlay,
]{\definedfont[SansItalic*default at 24bp]Workbook \getvariable{cover}{issue}}

\setlayerframed[whole][
  x=\measure{FrontTextstart},
  y=258mm,
  offset=overlay,
  %frame=off,
  width=16mm,
  height=16mm,
]{\startMPcode
  %input img/dvhlogo.mp;
  %draw DVHlogo_sw xysized (16mm,16mm);
  %redraw currentpicture withpen pencircle scaled 0.5bp withcolor "LineColor";
\stopMPcode}

\flushlayer[whole]

TEST

\stoplayout

\stoptext

[-- Attachment #5: Type: text/plain, Size: 493 bytes --]

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

  reply	other threads:[~2021-05-13 19:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 10:58 Henning Hraban Ramm
2021-05-11 11:30 ` Mikael Sundqvist
2021-05-11 12:33   ` Henning Hraban Ramm
2021-05-11 12:56   ` Jairo A. del Rio
2021-05-11 16:02     ` Aditya Mahajan
2021-05-12 18:07       ` Henning Hraban Ramm
2021-05-13 13:08       ` Henning Hraban Ramm
2021-05-13 16:36         ` Aditya Mahajan
2021-05-13 16:55           ` Henning Hraban Ramm
2021-05-13 17:17             ` Aditya Mahajan
2021-05-13 18:02               ` Henning Hraban Ramm
2021-05-13 18:26                 ` Thomas A. Schmitz
2021-05-13 19:42                   ` Henning Hraban Ramm [this message]
2021-05-14 15:08                     ` Thomas A. Schmitz
2021-05-13 22:39                 ` Aditya Mahajan
2021-05-14  9:43                   ` Hans Hagen
2021-05-14 20:33                   ` Henning Hraban Ramm
2021-09-03 16:04                 ` Henning Hraban Ramm via ntg-context
2022-01-21 18:00                   ` Iterating over MP paths (was: Fuzzy lines) Henning Hraban Ramm via ntg-context
2021-05-14 10:05           ` Fuzzy lines Hans Hagen
2021-05-12 17:55     ` Henning Hraban Ramm
     [not found]       ` <CAKyqqaaosis=BjOD_mArY5VM+bzcj-ar4uMtnt8SRJ2WLL9ykw@mail.gmail.com>
2021-05-12 21:21         ` Fwd: " Jairo A. del Rio
2021-05-13 13:23           ` Henning Hraban Ramm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E4947F06-28A3-4725-B62E-2C3D6134A509@fiee.net \
    --to=texml@fiee.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).