* update old MP code
@ 2022-09-01 7:29 Henning Hraban Ramm via ntg-context
2022-09-01 13:40 ` Taco Hoekwater via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-09-01 7:29 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm
[-- Attachment #1: Type: text/plain, Size: 1528 bytes --]
Hi,
here’s a snippet of old Metapost code that I’d like to use in ConTeXt.
I didn’t manage to update it to MetaFun – can you help me?
Hraban
-----
\setupbodyfont[plex,ss,8bp]
\startreusableMPgraphic{moiree}
% 1994 by Bogusław Jackowski (GUST)
defaultfont := "\truefontname{Sans}";
pickup pencircle scaled 0.3bp;
defaultscale := .8;
linecap := butt;
labeloffset := 1.5bp;
defaultthickness:=.3bp; % 5 pixels at 1200 dpi
% tertiarydef p ulshiftedto s = p shifted (s-ulcorner(p)) enddef;
def Moire(expr size)(text densities)=
save dn,a,b,k,labit,n,p,q,s,xs;
n := 32;
dn := 0;
for i := densities:
d[incr dn] := abs(i);
if i>1: labit[dn]:=1; fi
endfor
a := min(d[1],d[dn]);
b := max(d[1],d[dn]);
image(
for i=-n upto n:
draw (0,i*in/a)--(size,i*in/b);
%withpen pencircle scaled 3/5defaultthickness;
endfor
for i=1 upto dn:
k:=(a/d[i]-1)/(a/b-1);
if known labit[i]:
string s; s:=decimal(d[i]); xs:=0;
picture p,q; q := p := depthless(s);
if i=dn:
q := depthless(s & " lpi");
xs := width(q)-width(p);
fi
label.top(q, (k*size+1/2xs, n*in/a+1.5mm));
fi
draw (k*size, n*in/a+1.5mm)--(k*size, k[n*in/a,n*in/b]+.5mm);
draw (k*size, -n*in/a-1.5mm)--(k*size, -k[n*in/a,n*in/b]-.5mm);
endfor
)
enddef;
draw Moire(57.5mm)(200, 175, 150, 125, 100, 75);
% ulshiftedto (142mm, 38.5mm);
\stopreusableMPgraphic
\starttext
\reuseMPgraphic{moiree}
\stoptext
-----
[-- Attachment #2: moireetest.tex --]
[-- Type: application/x-tex, Size: 1338 bytes --]
[-- Attachment #3: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: update old MP code
2022-09-01 7:29 update old MP code Henning Hraban Ramm via ntg-context
@ 2022-09-01 13:40 ` Taco Hoekwater via ntg-context
2022-09-01 16:28 ` Henning Hraban Ramm via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-09-01 13:40 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Taco Hoekwater
Hi Hraban,
Adding grouping makes sense:
>
> def Moire(expr size)(text densities)=
begingroup
> save dn,a,b,k,labit,n,p,q,s,xs;
> n := 32;
> dn := 0;
> for i := densities:
> d[incr dn] := abs(i);
> if i>1: labit[dn]:=1; fi
> endfor
> a := min(d[1],d[dn]);
> b := max(d[1],d[dn]);
> image(
> for i=-n upto n:
> draw (0,i*in/a)--(size,i*in/b);
> %withpen pencircle scaled 3/5defaultthickness;
> endfor
> for i=1 upto dn:
> k:=(a/d[i]-1)/(a/b-1);
> if known labit[i]:
> string s; s:=decimal(d[i]); xs:=0;
> picture p,q; q := p := depthless(s);
> if i=dn:
> q := depthless(s & " lpi");
> xs := width(q)-width(p);
> fi
> label.top(q, (k*size+1/2xs, n*in/a+1.5mm));
> fi
> draw (k*size, n*in/a+1.5mm)--(k*size, k[n*in/a,n*in/b]+.5mm);
> draw (k*size, -n*in/a-1.5mm)--(k*size, -k[n*in/a,n*in/b]-.5mm);
> endfor
> )
endgroup
> enddef;
> draw Moire(57.5mm)(200, 175, 150, 125, 100, 75);
> % ulshiftedto (142mm, 38.5mm);
> \stopreusableMPgraphic
As that at least makes it an expression instead of a statement list.
But also depthless() is never defined?
—
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: update old MP code
2022-09-01 13:40 ` Taco Hoekwater via ntg-context
@ 2022-09-01 16:28 ` Henning Hraban Ramm via ntg-context
2022-09-01 16:45 ` Taco Hoekwater via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-09-01 16:28 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm
[-- Attachment #1: Type: text/plain, Size: 1983 bytes --]
Am 01.09.22 um 15:40 schrieb Taco Hoekwater:
> Adding grouping makes sense:
>>
>> def Moire(expr size)(text densities)=
>
> begingroup
> endgroup
>
> As that at least makes it an expression instead of a statement list.
>
> But also depthless() is never defined?
Oops, I forgot to copy that part (confusing source...)
It still doesn’t compile:
---
\setupbodyfont[plex,ss,8bp]
\startreusableMPgraphic{moiree}
% 1994 by Bogusław Jackowski (GUST)
defaultfont := "\truefontname{Sans}";
pickup pencircle scaled 0.3bp;
defaultscale := .8;
linecap := butt;
labeloffset := 1.5bp;
defaultthickness:=.3bp; % 5 pixels at 1200 dpi
% tertiarydef p ulshiftedto s = p shifted (s-ulcorner(p)) enddef;
vardef depthless(expr p) =
save p_; picture p_;
p_:=p if string p: infont defaultfont scaled defaultscale fi;
setbounds p_ to (xpart(llcorner p_),0)--(xpart(lrcorner p_),0)--
urcorner(p_)--ulcorner(p_)--cycle;
p_
enddef;
def Moire(expr size)(text densities)=
begingroup
save dn,a,b,k,labit,n,p,q,s,xs;
n := 32;
dn := 0;
for i := densities:
d[incr dn] := abs(i);
if i>1: labit[dn]:=1; fi
endfor
a := min(d[1],d[dn]);
b := max(d[1],d[dn]);
image(
for i=-n upto n:
draw (0,i*in/a)--(size,i*in/b);
%withpen pencircle scaled 3/5defaultthickness;
endfor
for i=1 upto dn:
k:=(a/d[i]-1)/(a/b-1);
if known labit[i]:
string s; s:=decimal(d[i]); xs:=0;
picture p,q; q := p := depthless(s);
if i=dn:
q := depthless(s & " lpi");
xs := width(q)-width(p);
fi
label.top(q, (k*size+1/2xs, n*in/a+1.5mm));
fi
draw (k*size, n*in/a+1.5mm)--(k*size, k[n*in/a,n*in/b]+.5mm);
draw (k*size, -n*in/a-1.5mm)--(k*size, -k[n*in/a,n*in/b]-.5mm);
endfor
)
endgroup;
enddef;
draw Moire(57.5mm)(200, 175, 150, 125, 100, 75);
% ulshiftedto (142mm, 38.5mm);
\stopreusableMPgraphic
\starttext
\reuseMPgraphic{moiree}
\stoptext
[-- Attachment #2: moireetest.tex --]
[-- Type: application/x-tex, Size: 1590 bytes --]
[-- Attachment #3: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: update old MP code
2022-09-01 16:28 ` Henning Hraban Ramm via ntg-context
@ 2022-09-01 16:45 ` Taco Hoekwater via ntg-context
2022-09-01 16:48 ` Henning Hraban Ramm via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-09-01 16:45 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Taco Hoekwater
> On 1 Sep 2022, at 18:28, Henning Hraban Ramm via ntg-context <ntg-context@ntg.nl> wrote:
>
> Am 01.09.22 um 15:40 schrieb Taco Hoekwater:
>> Adding grouping makes sense:
>>>
>>> def Moire(expr size)(text densities)=
>> begingroup
>> endgroup
>> As that at least makes it an expression instead of a statement list.
>> But also depthless() is never defined?
>
> Oops, I forgot to copy that part (confusing source...)
>
> It still doesn’t compile:
Missing definition of “width()”, from this line:
>
> xs := width(q)-width(p);
Adding that should do the trick.
Best wishes.
Taco
—
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: update old MP code
2022-09-01 16:45 ` Taco Hoekwater via ntg-context
@ 2022-09-01 16:48 ` Henning Hraban Ramm via ntg-context
0 siblings, 0 replies; 5+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-09-01 16:48 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm
[-- Attachment #1: Type: text/plain, Size: 789 bytes --]
Am 01.09.22 um 18:45 schrieb Taco Hoekwater:
>
>
>> On 1 Sep 2022, at 18:28, Henning Hraban Ramm via ntg-context <ntg-context@ntg.nl> wrote:
>>
>> Am 01.09.22 um 15:40 schrieb Taco Hoekwater:
>>> Adding grouping makes sense:
>>>>
>>>> def Moire(expr size)(text densities)=
>>> begingroup
>>> endgroup
>>> As that at least makes it an expression instead of a statement list.
>>> But also depthless() is never defined?
>>
>> Oops, I forgot to copy that part (confusing source...)
>>
>> It still doesn’t compile:
>
> Missing definition of “width()”, from this line:
>
>>
>> xs := width(q)-width(p);
>
> Adding that should do the trick.
YES, thank you!
I never know which function is part of MetaPost/MetaFun, my editor’s
syntax highlighting is incomplete...
Hraban
[-- Attachment #2: moireetest.tex --]
[-- Type: application/x-tex, Size: 1715 bytes --]
[-- Attachment #3: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-01 16:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 7:29 update old MP code Henning Hraban Ramm via ntg-context
2022-09-01 13:40 ` Taco Hoekwater via ntg-context
2022-09-01 16:28 ` Henning Hraban Ramm via ntg-context
2022-09-01 16:45 ` Taco Hoekwater via ntg-context
2022-09-01 16:48 ` Henning Hraban Ramm via ntg-context
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).