ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henning Hraban Ramm via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Henning Hraban Ramm <texml@fiee.net>
Subject: Re: Fuzzy lines
Date: Fri, 3 Sep 2021 18:04:22 +0200	[thread overview]
Message-ID: <D47272DD-83D4-4153-A928-3300BE7610AA@fiee.net> (raw)
In-Reply-To: <D475154D-8B65-45A7-BA63-E5DF1A0FADCA@fiee.net>

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


> Am 13.05.2021 um 20:02 schrieb Henning Hraban Ramm <texml@fiee.net>:
> 
> 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



[-- Attachment #2: sketchtest2.pdf --]
[-- Type: application/pdf, Size: 12857 bytes --]

[-- Attachment #3: mp-sketch.mp --]
[-- Type: application/octet-stream, Size: 3812 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
                   sketchrandomized 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 #4: 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
___________________________________________________________________________________

  parent reply	other threads:[~2021-09-03 16:04 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
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 [this message]
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=D47272DD-83D4-4153-A928-3300BE7610AA@fiee.net \
    --to=ntg-context@ntg.nl \
    --cc=texml@fiee.net \
    /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).