[NTG-context] MetaPost lines in tables?

2024-02-19 Thread Henning Hraban Ramm

I guess I asked this a while ago, but I can’t find an answer:
Is it possible to replace the lines of a TABLE with my own MetaPost 
graphics?


ATM I’m trying to place my MP lines behind a frame-less TABLE; it will 
probably work, but it’s a crutch…


Hraban
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Metapost docs

2024-01-07 Thread Shiv Shankar Dayal
I see many libraries for Metapost in Context source. Where are these
documented? I see Metafun manual as well, but I do not find all the
included libraries described.

-- 
Respect,
Shiv Shankar Dayal
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Metapost: draw only subpath; changing thickness of line

2024-01-05 Thread Emanuel Han via ntg-context
Hi all,

I have this MWE. Now I want to draw only the subpath of S between gong6 and 
gong7 with a red line which is narrower at the two ends and thicker in the 
middle part. How to achieve this?
Thanks!
Emanuel

\setuppapersize[A4,landscape]
\starttext
\startMPcode
numeric u; u=1cm;
%equiangular spiral
numeric a, k ;
a = 2.3; %scaling factor
k = 8.61722335;
path S;
S = right for t=1 upto 360: .. a ** (t/50.2) * dir (-k*t) endfor;
draw S;

z1 = 8 dir -14;
path A; A = origin -- z1 scaled 0.7u ; draw A;
pair AEndPoint; AEndPoint = point 1 of A;
pair gong[], times; numeric n; n = 0;
for i = 1 upto length(A):
for j = 1 upto length(S):
times := subpath (i-1,i) of A intersectiontimes subpath (j-1,j) of S;
if xpart times > -1:
gong[incr n] = 1/2[point xpart times of subpath (i-1,i) of A,
point ypart times of subpath (j-1,j) of S];
fi
endfor
endfor

dotlabel.rt ("$gong6$", gong6);
dotlabel.rt ("$gong7$", gong7);

%Now I want to draw only the subpath of S between gong6 and gong7 with a red 
line which is narrower at the two ends and thicker in the middle part
\stopMPcode
\stoptext___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Metapost label text surrounded by white border

2023-11-19 Thread Emanuel Han via ntg-context
I'd like to surround black text with a white 1mm thick border in a Metapost 
label. Here is my code, which doesn't draw the border at all and which draws 
the text in white instead of black (I'm using mkiv and mkxl version 2023.09.26 
18:19 on osx-arm6):

beginfig(1);
% Define the text and colors
string label_text;
label_text = "Your Text";
color text_color, border_color;
text_color = black;
border_color = white;
% Draw the label with the specified colors
label(textext(label_text) scaled 1.0, origin) withcolor text_color withpen 
pencircle scaled 1mm withcolor border_color;
endfig;___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] [ metapost -> svg ]

2023-11-05 Thread vm via ntg-context



With the latest lmtx installed, what would be the correct cli command to 
generate a svg outputfile from a metapost source?


.Floris
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


Re: [NTG-context] MetaPost cutdraw

2022-07-06 Thread Mikael Sundqvist via ntg-context
Hi,

On Wed, Jul 6, 2022 at 11:29 AM Henning Hraban Ramm via ntg-context
 wrote:
>
> Am 06.07.22 um 09:15 schrieb Hans Hagen via ntg-context:
> > On 7/6/2022 7:10 AM, Aditya Mahajan via ntg-context wrote:
> >> On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:
> >>
> >>> Hi, I’m trying to understand MetaPost better.
> >>>
> >>> I’d like to draw a fat line that’s cut at its end points.
> >>
> >> You mean like linecap = butt?
>
> Yes, but that doesn’t behave differently.
>
>
> > \startMPpage[offset=5mm]
> >  path p;
> >
> >  p := origin -- (7cm,0);
> >
> >  interim  linecap := squared;
> >
> >  draw p withpen ((pensquare) scaled 5mm) withcolor red ;
> >  draw envelope  ((pensquare) scaled 5mm) of p withcolor
> > green ;
> >  draw envelope  ((pensquare rotated eps) scaled 5mm) of p withcolor
> > blue ;
> > \stopMPpage
> >
> > (there is an "ontarget" chapter about envelopes; mikael and i spent
> > quite some time figuring out a few things but in the end conclused that
> > mp des the right thing given the strategy it folows but it definitely
> > has side effects)
>
> Thank you for the insight, but does that mean I can’t get my “butt
> capped” lines and I must shorten the lines by half the pen size?
>
> 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
> ___

Hraban,

with the new upload you can do

\startMPpage[offset=1dk]
pickup pencircle scaled 4 ;
path p ; p := origin -- (20,0) ;
draw p withcolor darkyellow ;
draw p yshifted 5 withlinecap butt withcolor darkred ;
draw p yshifted -5 withlinecap squared withcolor darkgreen ;
for i within currentpicture :
drawpoints pathpart i withpen pencircle scaled 1 ;
endfor ;
\stopMPpage

That is, you can set linecap for each draw. I hope it helps.

/Mikael
___
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] MetaPost label font size

2022-07-06 Thread Henning Hraban Ramm via ntg-context

Am 06.07.22 um 15:24 schrieb Fabrice L:

Here are slightly different syntax that could be useful perhaps ? In the second 
one, the scaled parameter can be replaced easily with a variable, so you can 
decide and change the size of the label during the course of a picture.


Thank you (all), I resolved to using the usual \tfx or \definedfont.

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] MetaPost label font size

2022-07-06 Thread Fabrice L via ntg-context


> Le 5 juill. 2022 à 19:00, Henning Hraban Ramm via ntg-context 
>  a écrit :
> 
> How can I change the font size of labels within one picture?
> 
> Hraban
> 
> \startMPpage
> defaultfont := "\truefontname{Sans}";
> defaultfontsize := \the\bodyfontsize;
> 
> label.top(defaultfontsize, (0,0));
> 
> defaultfontsize := 4bp;
> 
> label.top(defaultfontsize, (50,0));
> % shows that the variable changed,
> % but font size is the same
> 
> \stopMPpage

Here are slightly different syntax that could be useful perhaps ? In the second 
one, the scaled parameter can be replaced easily with a variable, so you can 
decide and change the size of the label during the course of a picture.

\starttext

\startMPpage
defaultfont := "\truefontname{Sans}";
defaultfontsize := \the\bodyfontsize;

defaultscale := 0.5;
label.top("small label", (-10,0));

defaultscale := 1.0;
label.top("normal label", (50,5));
label.top("another normal label", (50,-5));

defaultscale := 2.0;
label.top("Huge label", (10,-25));

\stopMPpage

\startMPpage

 draw textext.top("small label") scaled 0.5 
shifted (-10,0) ;
 draw textext.top("normal label") scaled 1 
shifted (50,5) ;
 draw textext.top("second normal label") scaled 1 
shifted (50,-5) ;
 draw textext.top("Huge label") scaled 2 
shifted (10,-25) ;

\stopMPpage

\stoptext

Fabrice.


___
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] MetaPost label font size

2022-07-06 Thread Hans Hagen via ntg-context

On 7/6/2022 1:36 PM, Henning Hraban Ramm via ntg-context wrote:

Am 06.07.22 um 12:45 schrieb Hans Hagen via ntg-context:

On 7/6/2022 12:19 PM, fv leung via ntg-context wrote:

My stupid way to get labels of different sizes:

\starttext

\startMPcode

   label("normal label", (0, 0));

   label("\setsmallbodyfont small label", (0, 18));

   label("\setbigbodyfont big label", (0, -18));

\stopMPcode

\stoptext

nothing stupid about that ... it's how i would do it


Okay. So there’s really no possibility to adapt whatever defines the 
label font size except defaultfontsize inbetween? Strange.


My solution so far was to split the picture and re-combine it afterwards.
well, if there would be another way you would find it strange there if 
that would interfere with whatever else goes into a label text because 
we support arbitrary tex ... no way to figure out what struts, line 
distances, spacing, either of not adapt to current situation, delayed vs 
immediate inclusion, etc ... you can't have both worlds


if course you can make some macro (or define a highlight) and use that 
in the labels


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] MetaPost label font size

2022-07-06 Thread fv leung via ntg-context
I've used something like the following before.


\starttext

\startMPcode

  label("normal label", (0, 0));

  label("{\switchtobodyfont[3pt] tiny label}", (0, 18));

  label("{\switchtobodyfont[72pt] giant label}", (0, -72));

\stopMPcode

\stoptext

Henning Hraban Ramm via ntg-context  於 2022年7月6日 週三
晚上7:36寫道:

> Am 06.07.22 um 12:45 schrieb Hans Hagen via ntg-context:
> > On 7/6/2022 12:19 PM, fv leung via ntg-context wrote:
> >> My stupid way to get labels of different sizes:
> >>
> >> \starttext
> >>
> >> \startMPcode
> >>
> >>label("normal label", (0, 0));
> >>
> >>label("\setsmallbodyfont small label", (0, 18));
> >>
> >>label("\setbigbodyfont big label", (0, -18));
> >>
> >> \stopMPcode
> >>
> >> \stoptext
> > nothing stupid about that ... it's how i would do it
>
> Okay. So there’s really no possibility to adapt whatever defines the
> label font size except defaultfontsize inbetween? Strange.
>
> My solution so far was to split the picture and re-combine it afterwards.
>
> 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
___


Re: [NTG-context] MetaPost label font size

2022-07-06 Thread Henning Hraban Ramm via ntg-context

Am 06.07.22 um 12:45 schrieb Hans Hagen via ntg-context:

On 7/6/2022 12:19 PM, fv leung via ntg-context wrote:

My stupid way to get labels of different sizes:

\starttext

\startMPcode

   label("normal label", (0, 0));

   label("\setsmallbodyfont small label", (0, 18));

   label("\setbigbodyfont big label", (0, -18));

\stopMPcode

\stoptext

nothing stupid about that ... it's how i would do it


Okay. So there’s really no possibility to adapt whatever defines the 
label font size except defaultfontsize inbetween? Strange.


My solution so far was to split the picture and re-combine it afterwards.

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] MetaPost label font size

2022-07-06 Thread Hans Hagen via ntg-context

On 7/6/2022 12:19 PM, fv leung via ntg-context wrote:

My stupid way to get labels of different sizes:

\starttext

\startMPcode

   label("normal label", (0, 0));

   label("\setsmallbodyfont small label", (0, 18));

   label("\setbigbodyfont big label", (0, -18));

\stopMPcode

\stoptext

nothing stupid about that ... it's how i would do it

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] MetaPost label font size

2022-07-06 Thread fv leung via ntg-context
My stupid way to get labels of different sizes:

\starttext

\startMPcode

  label("normal label", (0, 0));

  label("\setsmallbodyfont small label", (0, 18));

  label("\setbigbodyfont big label", (0, -18));

\stopMPcode

\stoptext

Henning Hraban Ramm via ntg-context  於 2022年7月6日 週三
下午5:23寫道:

> Am 06.07.22 um 07:17 schrieb Aditya Mahajan via ntg-context:
> > On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:
> >
> >> How can I change the font size of labels within one picture?
> >
> > (Untested): See https://www.contextgarden.net/Command/setupMPinstance
> >
> > \setupMPinstance[metafun][textstyle=sans]
> >
> > Or define a new instance, which sets the textstyle to sans.
>
> Thank you for trying, but that doesn’t seem to have anything to do with
> my question.
>
> I need a different font size for different labels within one picture.
>
> 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
___


Re: [NTG-context] MetaPost cutdraw

2022-07-06 Thread Henning Hraban Ramm via ntg-context

Am 06.07.22 um 09:15 schrieb Hans Hagen via ntg-context:

On 7/6/2022 7:10 AM, Aditya Mahajan via ntg-context wrote:

On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:


Hi, I’m trying to understand MetaPost better.

I’d like to draw a fat line that’s cut at its end points.


You mean like linecap = butt?


Yes, but that doesn’t behave differently.



\startMPpage[offset=5mm]
     path p;

     p := origin -- (7cm,0);

     interim  linecap := squared;

     draw p withpen ((pensquare    ) scaled 5mm) withcolor red ;
     draw envelope  ((pensquare    ) scaled 5mm) of p withcolor 
green ;
     draw envelope  ((pensquare rotated eps) scaled 5mm) of p withcolor 
blue ;

\stopMPpage

(there is an "ontarget" chapter about envelopes; mikael and i spent 
quite some time figuring out a few things but in the end conclused that 
mp des the right thing given the strategy it folows but it definitely 
has side effects)


Thank you for the insight, but does that mean I can’t get my “butt 
capped” lines and I must shorten the lines by half the pen size?


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] MetaPost label font size

2022-07-06 Thread Henning Hraban Ramm via ntg-context

Am 06.07.22 um 07:17 schrieb Aditya Mahajan via ntg-context:

On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:


How can I change the font size of labels within one picture?


(Untested): See https://www.contextgarden.net/Command/setupMPinstance

\setupMPinstance[metafun][textstyle=sans]

Or define a new instance, which sets the textstyle to sans.


Thank you for trying, but that doesn’t seem to have anything to do with 
my question.


I need a different font size for different labels within one picture.

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] MetaPost cutdraw

2022-07-06 Thread Hans Hagen via ntg-context

On 7/6/2022 7:10 AM, Aditya Mahajan via ntg-context wrote:

On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:


Hi, I’m trying to understand MetaPost better.

I’d like to draw a fat line that’s cut at its end points.


You mean like linecap = butt?

\startMPpage[offset=5mm]
   path p;

   p := origin -- (7cm,0);
   interim  linecap := butt;
   draw p withpen pencircle scaled 5mm;

   p := p shifted (0,2cm);
   interim  linecap := rounded;
   draw p withpen pencircle scaled 5mm;

   p := p shifted (0,2cm);
   interim  linecap := squared;
   draw p withpen pencircle scaled 5mm;

\stopMPpage


I learned, “cutdraw” should do the trick, but I get a parallelogram
instead of a rectangle.


Seems to be something weird with pensquare:

\startMPpage[offset=5mm]
   path p;

   p := origin -- (7cm,0);
   % interim  linecap := butt;
   cutdraw p withpen pensquare scaled 5mm;

   p := p shifted (0,2cm);
   interim  linecap := rounded;
   draw p withpen pensquare scaled 5mm;

   p := p shifted (0,2cm);
   interim  linecap := squared;
   draw p withpen pensquare scaled 5mm;

\stopMPpage

\startMPpage[offset=5mm]
path p;

p := origin -- (7cm,0);

interim  linecap := squared;

draw p withpen ((pensquare) scaled 5mm) withcolor red ;
draw envelope  ((pensquare) scaled 5mm) of p withcolor 
green ;
draw envelope  ((pensquare rotated eps) scaled 5mm) of p withcolor 
blue ;

\stopMPpage

(there is an "ontarget" chapter about envelopes; mikael and i spent 
quite some time figuring out a few things but in the end conclused that 
mp des the right thing given the strategy it folows but it definitely 
has side effects)


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] MetaPost label font size

2022-07-05 Thread Aditya Mahajan via ntg-context
On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:

> How can I change the font size of labels within one picture?

(Untested): See https://www.contextgarden.net/Command/setupMPinstance

\setupMPinstance[metafun][textstyle=sans]

Or define a new instance, which sets the textstyle to sans.

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] MetaPost cutdraw

2022-07-05 Thread Aditya Mahajan via ntg-context
On Wed, 6 Jul 2022, Henning Hraban Ramm via ntg-context wrote:

> Hi, I’m trying to understand MetaPost better.
> 
> I’d like to draw a fat line that’s cut at its end points.

You mean like linecap = butt?

\startMPpage[offset=5mm]
  path p;

  p := origin -- (7cm,0);
  interim  linecap := butt;
  draw p withpen pencircle scaled 5mm;

  p := p shifted (0,2cm);
  interim  linecap := rounded;
  draw p withpen pencircle scaled 5mm;

  p := p shifted (0,2cm);
  interim  linecap := squared;
  draw p withpen pencircle scaled 5mm;

\stopMPpage

> I learned, “cutdraw” should do the trick, but I get a parallelogram 
> instead of a rectangle.

Seems to be something weird with pensquare:

\startMPpage[offset=5mm]
  path p;

  p := origin -- (7cm,0);
  % interim  linecap := butt;
  cutdraw p withpen pensquare scaled 5mm;

  p := p shifted (0,2cm);
  interim  linecap := rounded;
  draw p withpen pensquare scaled 5mm;

  p := p shifted (0,2cm);
  interim  linecap := squared;
  draw p withpen pensquare scaled 5mm;

\stopMPpage

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
___


[NTG-context] MetaPost label font size

2022-07-05 Thread Henning Hraban Ramm via ntg-context

How can I change the font size of labels within one picture?

Hraban

\startMPpage
defaultfont := "\truefontname{Sans}";
defaultfontsize := \the\bodyfontsize;

label.top(defaultfontsize, (0,0));

defaultfontsize := 4bp;

label.top(defaultfontsize, (50,0));
% shows that the variable changed,
% but font size is the same

\stopMPpage
___
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] MetaPost cutdraw

2022-07-05 Thread Henning Hraban Ramm via ntg-context

Hi, I’m trying to understand MetaPost better.

I’d like to draw a fat line that’s cut at its end points.
I learned, “cutdraw” should do the trick, but I get a parallelogram 
instead of a rectangle.


What’s wrong?

Hraban


\startMPpage

draw (0,20)--(20,20) withpen pensquare scaled 10;

cutdraw (0,0)--(20,0) withpen pensquare scaled 10;

% just to show start and end
draw (0,-10)--(0,30);
draw (20,-10)--(20,30);

\stopMPpage
___
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] Metapost examples seems broken

2022-05-22 Thread Bruce Horrocks via ntg-context
It's archived here


which might suffice until the author gets his certificates sorted out?


> On 22 May 2022, at 09:41, Jan-Erik Hägglöf via ntg-context 
>  wrote:
> 
> HI!
> 
> I have issues to access the very most useful place to get inspiration to 
> write MetaFun code.
> 
> Google Chrome reports security issues
> 
> Maybe this could be off topic in this forum, if so, My apologize in advance. 
> But maybe someone knows the author of this site
> 
> https://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html
> 

—
Bruce Horrocks
Hampshire, UK

___
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] Metapost examples seems broken

2022-05-22 Thread Jan-Erik Hägglöf via ntg-context
HI!

I have issues to access the very most useful place to get inspiration to write 
MetaFun code.

Google Chrome reports security issues

Maybe this could be off topic in this forum, if so, My apologize in advance. 
But maybe someone knows the author of this site

https://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html 




/Jan-Erik___
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] MetaPost Examples

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

> Am 01.09.2021 um 14:45 schrieb Hans Hagen via ntg-context 
> :
> 
> On 9/1/2021 2:19 PM, Henning Hraban Ramm via ntg-context wrote:
>> Hi, I’m trying to “translate” the documentation of “fiziko”* from LaTeX to 
>> ConTeXt and would like to avoid the doubling of MP code like:
>> \startMP
>> path p;
>> p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
>> draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
>> \stopMP
>> \startMPcode
>> path p;
>> p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
>> draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
>> \stopMPcode
>> I’m quite sure there’s a possibility with buffers, but how?
>> \startbuffer
>> path p;
>> p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
>> draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
>> \stopbuffer
>> \typebuffer
>> ... and then how do I get the MP graphic?
> \processMPbuffer

“of course”

Thank you!

Used here: https://github.com/fiee/fiziko/blob/master/fiziko.mkiv

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] MetaPost Examples

2021-09-01 Thread Hans Hagen via ntg-context

On 9/1/2021 2:19 PM, Henning Hraban Ramm via ntg-context wrote:

Hi, I’m trying to “translate” the documentation of “fiziko”* from LaTeX to 
ConTeXt and would like to avoid the doubling of MP code like:

\startMP
 path p;
 p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
 draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
\stopMP

\startMPcode
 path p;
 p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
 draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
\stopMPcode

I’m quite sure there’s a possibility with buffers, but how?

\startbuffer
 path p;
 p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
 draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
\stopbuffer

\typebuffer

... and then how do I get the MP graphic?

\processMPbuffer


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


[NTG-context] MetaPost Examples

2021-09-01 Thread Henning Hraban Ramm via ntg-context
Hi, I’m trying to “translate” the documentation of “fiziko”* from LaTeX to 
ConTeXt and would like to avoid the doubling of MP code like:

\startMP
path p;
p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
\stopMP

\startMPcode
path p;
p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
\stopMPcode

I’m quite sure there’s a possibility with buffers, but how?

\startbuffer
path p;
p := (0,0){dir(30)}..(5cm, 0)..{dir(30)}(10cm, 0);
draw brush (p)(2minStrokeWidth*sin(offsetPathLength*pi));
\stopbuffer

\typebuffer

... and then how do I get the MP graphic?


Hraban

*) https://github.com/jemmybutton/fiziko
___
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] Metapost Animation of Sine

2021-07-22 Thread Otared Kavian
Hi Jeroen,

Unfortunately I am not familiar with Tikz, since all my documents use what is 
built-in ConTeXt and Metapost…
That being said I am sure someone on the list can help you with Tikz module.

Best regards: Otared

> On 22 Jul 2021, at 14:28, Jeroen  wrote:
> 
> Hi, both solutions are great! This is what I had in mind, a rolling sine. Is 
> there a way to get the same result with the Tikz module?
> 
> \usemodule[animation]
> \setupinteraction[state=start]
> 
> \starttext
> 
> \input tufte
> 
> \framed{
> \startanimation[menu=yes,framerate=40]
> \dorecurse{50}{\expanded
> {\startframe
> \startMPcode
> numeric u, omega, mylength, tt ;
> u := 2cm ;
> omega := 4 ;
> mylength := 3.141596 ;
> tt := \recurselevel ;
> path p ;
> p := (0u,sin(omega*(mylength/100)*tt)*u) for i = 1 upto 100 : 
> .. (((mylength/100)*i)*u,sin(omega*(mylength/100)*(i + tt))*u) 
> endfor ;
> draw p withpen pencircle scaled .5pt withcolor darkred ;
> \stopMPcode
> \stopframe}
> }
> \stopanimation
> }
> 
> \stoptext
> 
> Op wo 21 jul. 2021 om 23:26 schreef Otared Kavian  >:
> Hi, 
> 
> I wonder whether something like the following is what you are looking for:
> 
> % begin wave-sine.tex
> \usemodule[animation]
> \setupinteraction[state=start]
> \starttext
> \startTEXpage[offset=2pt]
> \startanimation[menu=yes,framerate=10]
> \dorecurse{100}{\expanded
> {\startframe
> \startMPcode
> numeric u, omega, mylength, tt ;
> u := 2cm ;
> omega := 4 ;
> mylength := 3.141596 ;
> tt := \recurselevel ;
> path p ;
> p := (0u,sin(omega*(mylength/100)*tt)*u) for i = 1 
> upto 100 : 
> .. 
> (((mylength/100)*i)*u,sin(omega*(mylength/100)*(i + tt))*u) 
> endfor ;
> draw p withpen pencircle scaled .5pt withcolor 
> darkred ;
> \stopMPcode
> \stopframe}
> }
> \stopanimation
> \stopTEXpage
> \stoptext
> % end wave-sine.tex
> 
> Best regards: OK
> 
> > On 21 Jul 2021, at 19:44, Jeroen  > > wrote:
> > 
> > I am looking for a sine animation as the one file f.pdf on this site
> > 
> > http://www.12000.org/my_notes/Mathematica_animation_into_PDF_using_latex/index.htm
> >  
> > 
> > 
> > Jeroen
> > 
> > Op wo 21 jul. 2021 om 17:54 schreef Fabrice L  > >:
> > Hi,
> > 
> >> Le 21 juill. 2021 à 10:08, Jeroen  >> > a écrit :
> >> 
> >> I use this small animation to enlarge a circle
> >> 
> >> 
> >> \usemodule[animation]
> >> \setupinteraction[state=start]
> >> \starttext
> >> \startanimation[menu=yes,framerate=10]
> >> \dorecurse{7}{\expanded
> >>   {\startframe
> >> \startMPcode
> >> path p;
> >> numeric n, u;
> >> u := 1cm;
> >> n:=\recurselevel*u;
> >> p := fullcircle scaled n;
> >> draw p;
> >> \stopMPcode
> >>   \stopframe}}
> >> \stopanimation
> >> \stoptext
> >> 
> >> 
> >> This I use to draw a sine
> >> 
> >> 
> >> \starttext
> >> \startMPcode
> >>   draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> >> (i/360*1.5cm,0.9cm*(sind(i)))endfor;
> >> \stopMPcode
> >> \stoptext
> >> 
> >> 
> >> When I put it together to animate the sine as following, it does not 
> >> entirely create the sine animation I am looking for
> >> 
> >> 
> >> \usemodule[animation]
> >> \setupinteraction[state=start]
> >> \starttext
> >> \startanimation[menu=yes,framerate=10]
> >> \dorecurse{7}{\expanded
> >>   {\startframe
> >> \startMPcode
> >> path p;
> >> numeric n, u;
> >> u := 1cm;
> >> n:=\recurselevel*u;
> >> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> >> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> >> draw p;
> >> \stopMPcode
> >> \stopframe}}
> >> \stopanimation
> >> \stoptext
> >> 
> >> 
> >> What better way can I create a sine animation with Metapost?
> >>  
> >> 
> > 
> > Here is another way to do your animation. This is doing something, but I 
> > guess not what you want. Could you describe what do you have in mind ?
> > 
> > \starttext
> > \dorecurse{7}{ % 3180
> > \startMPpage
> >   myvariable := #1 ;
> >   path p;
> > numeric n, u;
> > u := 1cm;
> > n:=myvariable*u;
> > p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> > (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> > draw p;
> > \stopMPpage
> > }
> > \stoptext
> > 
> > Fabrice.
> > 
> > 
> > ___
> > If your question is of interest to others as well, please add an entry to 
> > the Wiki!
> > 
> > maillist : ntg-context@ntg.nl 

Re: [NTG-context] Metapost Animation of Sine

2021-07-22 Thread Jeroen
Hi, both solutions are great! This is what I had in mind, a rolling sine.
Is there a way to get the same result with the Tikz module?

\usemodule[animation]
\setupinteraction[state=start]

\starttext

\input tufte

\framed{
\startanimation[menu=yes,framerate=40]
\dorecurse{50}{\expanded
{\startframe
\startMPcode
numeric u, omega, mylength, tt ;
u := 2cm ;
omega := 4 ;
mylength := 3.141596 ;
tt := \recurselevel ;
path p ;
p := (0u,sin(omega*(mylength/100)*tt)*u) for i = 1 upto 100 :
.. (((mylength/100)*i)*u,sin(omega*(mylength/100)*(i + tt))*u)
endfor ;
draw p withpen pencircle scaled .5pt withcolor darkred ;
\stopMPcode
\stopframe}
}
\stopanimation
}

\stoptext

Op wo 21 jul. 2021 om 23:26 schreef Otared Kavian :

> Hi,
>
> I wonder whether something like the following is what you are looking for:
>
> % begin wave-sine.tex
> \usemodule[animation]
> \setupinteraction[state=start]
> \starttext
> \startTEXpage[offset=2pt]
> \startanimation[menu=yes,framerate=10]
> \dorecurse{100}{\expanded
> {\startframe
> \startMPcode
> numeric u, omega, mylength, tt ;
> u := 2cm ;
> omega := 4 ;
> mylength := 3.141596 ;
> tt := \recurselevel ;
> path p ;
> p := (0u,sin(omega*(mylength/100)*tt)*u) for i = 1
> upto 100 :
> ..
> (((mylength/100)*i)*u,sin(omega*(mylength/100)*(i + tt))*u)
> endfor ;
> draw p withpen pencircle scaled .5pt withcolor
> darkred ;
> \stopMPcode
> \stopframe}
> }
> \stopanimation
> \stopTEXpage
> \stoptext
> % end wave-sine.tex
>
> Best regards: OK
>
> > On 21 Jul 2021, at 19:44, Jeroen  wrote:
> >
> > I am looking for a sine animation as the one file f.pdf on this site
> >
> >
> http://www.12000.org/my_notes/Mathematica_animation_into_PDF_using_latex/index.htm
> >
> > Jeroen
> >
> > Op wo 21 jul. 2021 om 17:54 schreef Fabrice L :
> > Hi,
> >
> >> Le 21 juill. 2021 à 10:08, Jeroen  a écrit :
> >>
> >> I use this small animation to enlarge a circle
> >>
> >>
> >> \usemodule[animation]
> >> \setupinteraction[state=start]
> >> \starttext
> >> \startanimation[menu=yes,framerate=10]
> >> \dorecurse{7}{\expanded
> >>   {\startframe
> >> \startMPcode
> >> path p;
> >> numeric n, u;
> >> u := 1cm;
> >> n:=\recurselevel*u;
> >> p := fullcircle scaled n;
> >> draw p;
> >> \stopMPcode
> >>   \stopframe}}
> >> \stopanimation
> >> \stoptext
> >>
> >>
> >> This I use to draw a sine
> >>
> >>
> >> \starttext
> >> \startMPcode
> >>   draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
> (i/360*1.5cm,0.9cm*(sind(i)))endfor;
> >> \stopMPcode
> >> \stoptext
> >>
> >>
> >> When I put it together to animate the sine as following, it does not
> entirely create the sine animation I am looking for
> >>
> >>
> >> \usemodule[animation]
> >> \setupinteraction[state=start]
> >> \starttext
> >> \startanimation[menu=yes,framerate=10]
> >> \dorecurse{7}{\expanded
> >>   {\startframe
> >> \startMPcode
> >> path p;
> >> numeric n, u;
> >> u := 1cm;
> >> n:=\recurselevel*u;
> >> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> >> draw p;
> >> \stopMPcode
> >> \stopframe}}
> >> \stopanimation
> >> \stoptext
> >>
> >>
> >> What better way can I create a sine animation with Metapost?
> >>
> >>
> >
> > Here is another way to do your animation. This is doing something, but I
> guess not what you want. Could you describe what do you have in mind ?
> >
> > \starttext
> > \dorecurse{7}{ % 3180
> > \startMPpage
> >   myvariable := #1 ;
> >   path p;
> > numeric n, u;
> > u := 1cm;
> > n:=myvariable*u;
> > p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> > draw p;
> > \stopMPpage
> > }
> > \stoptext
> >
> > Fabrice.
> >
> >
> >
> ___
> > 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 / 

Re: [NTG-context] Metapost Animation of Sine

2021-07-21 Thread Otared Kavian
Hi,

Adding to my previous message, if you are looking for an animation of the wave 
equation for a string with fixed endpoints, one has to use something like the 
following:

% begin wave-sine-string.tex
\usemodule[animation]
\setupinteraction[state=start]
\starttext
\startTEXpage[offset=2pt]
\startanimation[menu=yes,framerate=10]
\dorecurse{101}{\expanded
{\startframe
\startMPcode
numeric u, omega, mylength, tt, N ;
u := 2cm ;
omega := 4 ;
mylength := 3.141596 ;
tt := \recurselevel - 1 ;
N := 500 ; % number of steps
path p ;
p := (0u,0u) for i = 1 upto N : 
-- 
(((mylength/N)*i)*u,cos(omega*(mylength/N)*tt)*sin(omega*(mylength/N)*i)*u) 
endfor ;
draw p withpen pencircle scaled .5pt withcolor darkred ;
\stopMPcode
\stopframe}
}
\stopanimation
\stopTEXpage
\stoptext
% end wave-sine-string.tex

Best regards: OK

> On 21 Jul 2021, at 19:44, Jeroen  wrote:
> 
> I am looking for a sine animation as the one file f.pdf on this site
> 
> http://www.12000.org/my_notes/Mathematica_animation_into_PDF_using_latex/index.htm
> 
> Jeroen
> 
> Op wo 21 jul. 2021 om 17:54 schreef Fabrice L :
> Hi,
> 
>> Le 21 juill. 2021 à 10:08, Jeroen  a écrit :
>> 
>> I use this small animation to enlarge a circle
>> 
>> 
>> \usemodule[animation]
>> \setupinteraction[state=start]
>> \starttext
>> \startanimation[menu=yes,framerate=10]
>> \dorecurse{7}{\expanded
>>   {\startframe
>> \startMPcode
>> path p;
>> numeric n, u;
>> u := 1cm;
>> n:=\recurselevel*u;
>> p := fullcircle scaled n;
>> draw p;
>> \stopMPcode
>>   \stopframe}}
>> \stopanimation
>> \stoptext
>> 
>> 
>> This I use to draw a sine
>> 
>> 
>> \starttext
>> \startMPcode
>>   draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
>> (i/360*1.5cm,0.9cm*(sind(i)))endfor;
>> \stopMPcode
>> \stoptext
>> 
>> 
>> When I put it together to animate the sine as following, it does not 
>> entirely create the sine animation I am looking for
>> 
>> 
>> \usemodule[animation]
>> \setupinteraction[state=start]
>> \starttext
>> \startanimation[menu=yes,framerate=10]
>> \dorecurse{7}{\expanded
>>   {\startframe
>> \startMPcode
>> path p;
>> numeric n, u;
>> u := 1cm;
>> n:=\recurselevel*u;
>> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
>> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
>> draw p;
>> \stopMPcode
>> \stopframe}}
>> \stopanimation
>> \stoptext
>> 
>> 
>> What better way can I create a sine animation with Metapost?
>>  
>> 
> 
> Here is another way to do your animation. This is doing something, but I 
> guess not what you want. Could you describe what do you have in mind ?
> 
> \starttext
> \dorecurse{7}{ % 3180
> \startMPpage
>   myvariable := #1 ;
>   path p;
> numeric n, u;
> u := 1cm;
> n:=myvariable*u;
> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> draw p;
> \stopMPpage
> }
> \stoptext
> 
> Fabrice.
> 
> 
> ___
> 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
> ___

___
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] Metapost Animation of Sine

2021-07-21 Thread Otared Kavian
Hi, 

I wonder whether something like the following is what you are looking for:

% begin wave-sine.tex
\usemodule[animation]
\setupinteraction[state=start]
\starttext
\startTEXpage[offset=2pt]
\startanimation[menu=yes,framerate=10]
\dorecurse{100}{\expanded
{\startframe
\startMPcode
numeric u, omega, mylength, tt ;
u := 2cm ;
omega := 4 ;
mylength := 3.141596 ;
tt := \recurselevel ;
path p ;
p := (0u,sin(omega*(mylength/100)*tt)*u) for i = 1 upto 
100 : 
.. 
(((mylength/100)*i)*u,sin(omega*(mylength/100)*(i + tt))*u) 
endfor ;
draw p withpen pencircle scaled .5pt withcolor darkred ;
\stopMPcode
\stopframe}
}
\stopanimation
\stopTEXpage
\stoptext
% end wave-sine.tex

Best regards: OK

> On 21 Jul 2021, at 19:44, Jeroen  wrote:
> 
> I am looking for a sine animation as the one file f.pdf on this site
> 
> http://www.12000.org/my_notes/Mathematica_animation_into_PDF_using_latex/index.htm
> 
> Jeroen
> 
> Op wo 21 jul. 2021 om 17:54 schreef Fabrice L :
> Hi,
> 
>> Le 21 juill. 2021 à 10:08, Jeroen  a écrit :
>> 
>> I use this small animation to enlarge a circle
>> 
>> 
>> \usemodule[animation]
>> \setupinteraction[state=start]
>> \starttext
>> \startanimation[menu=yes,framerate=10]
>> \dorecurse{7}{\expanded
>>   {\startframe
>> \startMPcode
>> path p;
>> numeric n, u;
>> u := 1cm;
>> n:=\recurselevel*u;
>> p := fullcircle scaled n;
>> draw p;
>> \stopMPcode
>>   \stopframe}}
>> \stopanimation
>> \stoptext
>> 
>> 
>> This I use to draw a sine
>> 
>> 
>> \starttext
>> \startMPcode
>>   draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
>> (i/360*1.5cm,0.9cm*(sind(i)))endfor;
>> \stopMPcode
>> \stoptext
>> 
>> 
>> When I put it together to animate the sine as following, it does not 
>> entirely create the sine animation I am looking for
>> 
>> 
>> \usemodule[animation]
>> \setupinteraction[state=start]
>> \starttext
>> \startanimation[menu=yes,framerate=10]
>> \dorecurse{7}{\expanded
>>   {\startframe
>> \startMPcode
>> path p;
>> numeric n, u;
>> u := 1cm;
>> n:=\recurselevel*u;
>> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
>> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
>> draw p;
>> \stopMPcode
>> \stopframe}}
>> \stopanimation
>> \stoptext
>> 
>> 
>> What better way can I create a sine animation with Metapost?
>>  
>> 
> 
> Here is another way to do your animation. This is doing something, but I 
> guess not what you want. Could you describe what do you have in mind ?
> 
> \starttext
> \dorecurse{7}{ % 3180
> \startMPpage
>   myvariable := #1 ;
>   path p;
> numeric n, u;
> u := 1cm;
> n:=myvariable*u;
> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> draw p;
> \stopMPpage
> }
> \stoptext
> 
> Fabrice.
> 
> 
> ___
> 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
> ___

___
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] Metapost Animation of Sine

2021-07-21 Thread Jeroen
I am looking for a sine animation as the one file f.pdf on this site

http://www.12000.org/my_notes/Mathematica_animation_into_PDF_using_latex/index.htm

Jeroen

Op wo 21 jul. 2021 om 17:54 schreef Fabrice L :

> Hi,
>
> Le 21 juill. 2021 à 10:08, Jeroen  a écrit :
>
> I use this small animation to enlarge a circle
>
>
> \usemodule[animation]
> \setupinteraction[state=start]
> \starttext
> \startanimation[menu=yes,framerate=10]
> \dorecurse{7}{\expanded
>   {\startframe
> \startMPcode
> path p;
> numeric n, u;
> u := 1cm;
> n:=\recurselevel*u;
> p := fullcircle scaled n;
> draw p;
> \stopMPcode
>   \stopframe}}
> \stopanimation
> \stoptext
>
>
> This I use to draw a sine
>
>
> \starttext
> \startMPcode
>   draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
> (i/360*1.5cm,0.9cm*(sind(i)))endfor;
> \stopMPcode
> \stoptext
>
>
> When I put it together to animate the sine as following, it does not
> entirely create the sine animation I am looking for
>
>
> \usemodule[animation]
> \setupinteraction[state=start]
> \starttext
> \startanimation[menu=yes,framerate=10]
> \dorecurse{7}{\expanded
>   {\startframe
> \startMPcode
> path p;
> numeric n, u;
> u := 1cm;
> n:=\recurselevel*u;
> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> draw p;
> \stopMPcode
> \stopframe}}
> \stopanimation
> \stoptext
>
>
> What better way can I create a sine animation with Metapost?
>
>
>
>
> Here is another way to do your animation. This is doing something, but I
> guess not what you want. Could you describe what do you have in mind ?
>
> \starttext
> \dorecurse{7}{ % 3180
> \startMPpage
> myvariable := #1 ;
> path p;
> numeric n, u;
> u := 1cm;
> n:=myvariable*u;
> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> draw p;
> \stopMPpage
> }
> \stoptext
>
> Fabrice.
>
>
>
> ___
> 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
___


Re: [NTG-context] Metapost Animation of Sine

2021-07-21 Thread Fabrice L
Hi,

> Le 21 juill. 2021 à 10:08, Jeroen  a écrit :
> 
> I use this small animation to enlarge a circle
> 
> 
> \usemodule[animation]
> \setupinteraction[state=start]
> \starttext
> \startanimation[menu=yes,framerate=10]
> \dorecurse{7}{\expanded
>   {\startframe
> \startMPcode
> path p;
> numeric n, u;
> u := 1cm;
> n:=\recurselevel*u;
> p := fullcircle scaled n;
> draw p;
> \stopMPcode
>   \stopframe}}
> \stopanimation
> \stoptext
> 
> 
> This I use to draw a sine
> 
> 
> \starttext
> \startMPcode
>   draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> (i/360*1.5cm,0.9cm*(sind(i)))endfor;
> \stopMPcode
> \stoptext
> 
> 
> When I put it together to animate the sine as following, it does not entirely 
> create the sine animation I am looking for
> 
> 
> \usemodule[animation]
> \setupinteraction[state=start]
> \starttext
> \startanimation[menu=yes,framerate=10]
> \dorecurse{7}{\expanded
>   {\startframe
> \startMPcode
> path p;
> numeric n, u;
> u := 1cm;
> n:=\recurselevel*u;
> p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
> (i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
> draw p;
> \stopMPcode
> \stopframe}}
> \stopanimation
> \stoptext
> 
> 
> What better way can I create a sine animation with Metapost?
>  
> 

Here is another way to do your animation. This is doing something, but I guess 
not what you want. Could you describe what do you have in mind ?

\starttext
\dorecurse{7}{ % 3180
\startMPpage
myvariable := #1 ;
path p;
numeric n, u;
u := 1cm;
n:=myvariable*u;
p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: .. 
(i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
draw p;
\stopMPpage
}
\stoptext

Fabrice.


___
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] Metapost Animation of Sine

2021-07-21 Thread Jeroen
I use this small animation to enlarge a circle


\usemodule[animation]
\setupinteraction[state=start]
\starttext
\startanimation[menu=yes,framerate=10]
\dorecurse{7}{\expanded
  {\startframe
\startMPcode
path p;
numeric n, u;
u := 1cm;
n:=\recurselevel*u;
p := fullcircle scaled n;
draw p;
\stopMPcode
  \stopframe}}
\stopanimation
\stoptext


This I use to draw a sine


\starttext
\startMPcode
  draw(-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
(i/360*1.5cm,0.9cm*(sind(i)))endfor;
\stopMPcode
\stoptext


When I put it together to animate the sine as following, it does not
entirely create the sine animation I am looking for


\usemodule[animation]
\setupinteraction[state=start]
\starttext
\startanimation[menu=yes,framerate=10]
\dorecurse{7}{\expanded
  {\startframe
\startMPcode
path p;
numeric n, u;
u := 1cm;
n:=\recurselevel*u;
p := (-90/360*1.5cm,-0.9cm) for i = -90 upto 630: ..
(i/360*1.5cm,0.9cm*(sind(i))) endfor shifted (n,0);
draw p;
\stopMPcode
\stopframe}}
\stopanimation
\stoptext


What better way can I create a sine animation with Metapost?
___
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] Metapost: directionpoint gives unexpected point(?)

2021-02-12 Thread Hans Hagen

Hi,

Like this:

metapost.registerscript("scrutenized", function()
local p = mp.scan.path()
local r = math.round
local d = 10^mp.scan.numeric()
for i=1,#p do
local pi = p[i]
pi[1] = r(pi[1] * d) / d
pi[2] = r(pi[2] * d) / d
end
local x1 = r(p[1][1])
local y1 = r(p[1][2])
local n = 1
local t = { p[1], cycle = p.cycle }
for i=2,#p do
local pi = p[i]
local x2 = r(pi[1])
local y2 = r(pi[2])
if x1 ~= x2 or y1 ~= y2 then
n = n + 1
t[n] = p[i]
x1 = x2
y1 = y2
end
end
mp.inject.path(t)
end)
\stopluacode

\startMPdefinitions{doublefun}
newscriptindex mfid_scrutenized ; mfid_scrutenized := scriptindex 
"scrutenized" ;


primarydef p scrutenized  n =
runscript mfid_scrutenized p n
enddef ;
\stopMPdefinitions

and then

p[1] := p[1] scrutenized 5 ; % 5 decimals
p[2] := p[2] scrutenized 5 ; % 5 decimals

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] Metapost: directionpoint gives unexpected point(?)

2021-02-12 Thread Taco Hoekwater


> On 12 Feb 2021, at 10:31, Mikael Sundqvist  wrote:
> 
> Hi Taco,
> 
> thanks, from your observation and the way I build the paths, I found
> out that I can avoid the problem by shortening the paths I join just
> slightly:
> 
> cl := (fullcircle scaled 4u) shifted z0;
> cl := cl cutbefore point (1/6+epsilon) along cl cutafter point
> (2/6-epsilon) along cl;
> cs := (fullcircle scaled 16u) shifted z1;
> cs := cs cutafter point (1/6-epsilon) along cs;
> 
> and indeed, it works here now, with different values of the scale u,
> and it seems more stable.


Here is a quick hack I wrote that does the cleanup in a postprocessing stage. 
It is not very generic or clever, but it works for your case:

def clean_path(suffix p) =
  begingroup;
  save q,precontrols,postcontrols,points, skip, i,j;
  boolean skip;
  pair precontrols[],postcontrols[],points[] ;
  j := 0;
  for i = 0 upto length p:
skip := false;
if abs(xpart point i of p - xpart point i+1 of p)<0.01:
   if abs(ypart point i of p - ypart point i+1 of p)<0.01:
 skip := true;
   fi
fi
if not skip:
   points[j] := point i of p;
   postcontrols[j] := postcontrol i of p;
   precontrols[j+1] := precontrol i+1 of p;
   j := j + 1;
fi
  endfor;
  if abs(xpart point 0 of p - xpart point length p of p)<0.01:
 if abs(ypart point 0 of p - ypart point length p of p)<0.01:
   j := j - 1;
 fi
  fi
  p := for i=0 upto j-1: points[i] .. controls postcontrols[i] and 
precontrols[i+1] .. endfor cycle;
  endgroup;
enddef;

show p0;
clean_path(p0);
show p0;

> 
> PS I found out that eps and epsilon both worked, and I do not see in
> the metafun manual if there is a difference.

The original intent was for eps to be just a ’small enough value that a human 
will not notice it’ where epsilon is intended as ’the smallest representable 
value’. Neither really work that way because depending on how you use metapost 
eps can be quite visible (especially in non-scaled number systems) and (more 
importantly) in the new non-scaled number systems epsilon cannot really be the 
smallest representable value for numerical and practical reasons.

So in reality, we always use these definitions:

  eps  := .00049 ;  % this is a pretty small positive number
  epsilon  := 1/256/256 


Best wishes,
Taco

— 
Taco Hoekwater  E: t...@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 / 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] Metapost: directionpoint gives unexpected point(?)

2021-02-12 Thread Hans Hagen

On 2/12/2021 9:35 AM, Taco Hoekwater wrote:

Hi,


On 11 Feb 2021, at 17:41, Mikael Sundqvist  wrote:

Thanks for your investigation and extended example!

So, if I understand it correctly, the problem occurs where the
different circles are glued together with the .. construction.


Took me a while to get it, but the problem is the definition of p0:

p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated 240) .. 
(cl rotated 240) .. cycle;

Here are cs and cl after your earlier definition:

cs := (141.732246,-49.097491614210789)
   ..(75.312386775380347,111.25424516116959)
   ..(28.347427842053655,147.2925755432174);

cl := (28.346108531095332,147.29283827977969)

   ..(0,154.88788322842163)
   ..(-28.346108531095332,147.29283827977969);

Note how the last point of cs and the first point of cl are nearly the same. 
When you combine these bits into p0, p0 becomes a cyclic path with 18 points 
(where you really want/need only 12 points).

The micro-segments between these nearly-identical paths are the problem. At 
smaller u values the differences between the points become zero, and the 
directionpoint of a path of length zero is mathematically undefined.

I do not know a quick generic solution off hand, but that is what the issue is.
Brilliant, as usual. So, now I can kick in with the dirty hackery (can 
be some proper thing but that's for later):


\starttext

\startluacode

function mp.foo()
local p = mp.scan.path()
local r = math.round
local d = 10
for i=1,#p do
local pi = p[i]
pi[1] = r(pi[1] * d) / d
pi[2] = r(pi[2] * d) / d
end
local x1 = r(p[1][1])
local y1 = r(p[1][2])
local n = 1
local t = { p[1], cycle = p.cycle }
for i=2,#p do
local x2 = r(p[i][1])
local y2 = r(p[i][2])
if x1 ~= x2 or y1 ~= y2 then
n = n + 1
t[n] = p[i]
x1 = x2
y1 = y2
end
end
--inspect(t)
mp.inject.path(t)
end

\stopluacode

\startMPdefinitions{doublefun}

def FOO(expr u) =

path p[];

% This defines the reulleaux curves
% p[0] is a "base" reulleaux curve
path cl,cs,rl ;
z0 = (0,6/sqrt(3)*u);
z1 = z0 rotated 120;
cl := (fullcircle scaled 4u) shifted z0;
cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
cs := (fullcircle scaled 16u) shifted z1;
cs := cs cutafter point 1/6 along cs;
p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs
rotated 240) .. (cl rotated 240) .. cycle;

% p[0] := runscript("mp.foo()") p[0];

% the first curve (darkyellow)
% p[1] := p[0] rotated 27 shifted (-10u,2u);
p[1] := p[0] rotated 27 shifted (-10u,2u);
draw p1 withpen pencircle scaled 2bp withcolor darkyellow;
% the second curve (darkblue)
p[2] := p[1] rotated 180;
draw p2 withpen pencircle scaled 2bp withcolor darkblue;

if true :

p[1] := runscript("mp.foo()") p[1];
p[2] := runscript("mp.foo()") p[2];

p3 := for phi=0 step 30 until 360: ((directionpoint dir(phi) of p1)
shifted (directionpoint dir(phi) of p2)) .. endfor cycle;
draw p3 withpen pencircle scaled 2bp withcolor darkred;

else :

drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of 
p1) -- endfor cycle withpen pencircle scaled 1bp withcolor darkgreen;
drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of 
p2) -- endfor cycle withpen pencircle scaled 1bp withcolor darkmagenta;

drawarrow for phi=0 step 30 until 360:
((directionpoint dir(phi) of p1) shifted (directionpoint 
dir(phi) of p2)) -- endfor cycle

withpen pencircle scaled 1bp withcolor darkred;

fi ;

% We give one direction as example
% These are merely here to show the construction of the curve
% But they also show what is going wrong

direx:=40;

z11=directionpoint dir(direx) of p1;
z22=directionpoint dir(direx) of p2;

p4 = ((-u,0)--(u,0)) rotated direx;

% These arrows should be tangent
drawarrow p4 shifted z11;
drawarrow p4 shifted z22;
drawarrow p4 shifted (z11 shifted z22);

% Draw the parallelogram.
draw origin -- z11 dashed evenly;
draw origin -- z22 dashed evenly;
draw z11 -- (z11 shifted z22) dashed evenly;
draw z22 -- (z11 shifted z22) dashed evenly;

enddef ;
\stopMPdefinitions

\startMPpage[offset=4bp,instance=doublefun]
FOO(1cm);
\stopMPpage
\startMPpage[offset=4bp,instance=doublefun]
FOO(.8cm);
\stopMPpage
\startMPpage[offset=4bp,instance=doublefun]
FOO(.5cm);
\stopMPpage
\startMPpage[offset=4bp,instance=doublefun]
FOO(.2cm);
\stopMPpage
\stoptext



-
  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 

Re: [NTG-context] Metapost: directionpoint gives unexpected point(?)

2021-02-12 Thread Mikael Sundqvist
Hi Taco,

thanks, from your observation and the way I build the paths, I found
out that I can avoid the problem by shortening the paths I join just
slightly:

cl := (fullcircle scaled 4u) shifted z0;
cl := cl cutbefore point (1/6+epsilon) along cl cutafter point
(2/6-epsilon) along cl;
cs := (fullcircle scaled 16u) shifted z1;
cs := cs cutafter point (1/6-epsilon) along cs;

and indeed, it works here now, with different values of the scale u,
and it seems more stable.

/Mikael

PS I found out that eps and epsilon both worked, and I do not see in
the metafun manual if there is a difference.

On Fri, Feb 12, 2021 at 9:35 AM Taco Hoekwater  wrote:
>
> Hi,
>
> > On 11 Feb 2021, at 17:41, Mikael Sundqvist  wrote:
> >
> > Thanks for your investigation and extended example!
> >
> > So, if I understand it correctly, the problem occurs where the
> > different circles are glued together with the .. construction.
>
> Took me a while to get it, but the problem is the definition of p0:
>
> p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated 240) 
> .. (cl rotated 240) .. cycle;
>
> Here are cs and cl after your earlier definition:
>
> cs := (141.732246,-49.097491614210789)
>   ..(75.312386775380347,111.25424516116959)
>   ..(28.347427842053655,147.2925755432174);
>
> cl := (28.346108531095332,147.29283827977969)
>   ..(0,154.88788322842163)
>   ..(-28.346108531095332,147.29283827977969);
>
> Note how the last point of cs and the first point of cl are nearly the same. 
> When you combine these bits into p0, p0 becomes a cyclic path with 18 points 
> (where you really want/need only 12 points).
>
> The micro-segments between these nearly-identical paths are the problem. At 
> smaller u values the differences between the points become zero, and the 
> directionpoint of a path of length zero is mathematically undefined.
>
> I do not know a quick generic solution off hand, but that is what the issue 
> is.
>
> Best wishes,
> Taco
>
>
> ___
> 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
___


Re: [NTG-context] Metapost: directionpoint gives unexpected point(?)

2021-02-12 Thread Taco Hoekwater
Hi,

> On 11 Feb 2021, at 17:41, Mikael Sundqvist  wrote:
> 
> Thanks for your investigation and extended example!
> 
> So, if I understand it correctly, the problem occurs where the
> different circles are glued together with the .. construction.

Took me a while to get it, but the problem is the definition of p0:

p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated 240) .. 
(cl rotated 240) .. cycle;

Here are cs and cl after your earlier definition:

cs := (141.732246,-49.097491614210789)
  ..(75.312386775380347,111.25424516116959)
  ..(28.347427842053655,147.2925755432174);
   
cl := (28.346108531095332,147.29283827977969)
  ..(0,154.88788322842163)
  ..(-28.346108531095332,147.29283827977969);

Note how the last point of cs and the first point of cl are nearly the same. 
When you combine these bits into p0, p0 becomes a cyclic path with 18 points 
(where you really want/need only 12 points).

The micro-segments between these nearly-identical paths are the problem. At 
smaller u values the differences between the points become zero, and the 
directionpoint of a path of length zero is mathematically undefined. 

I do not know a quick generic solution off hand, but that is what the issue is.

Best wishes,
Taco


___
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] Metapost: directionpoint gives unexpected point(?)

2021-02-11 Thread Mikael Sundqvist
Thanks for your investigation and extended example!

So, if I understand it correctly, the problem occurs where the
different circles are glued together with the .. construction.

I will wait to see if Alan or somebody else has an idea of a nice
solution to the problem.

/Mikael

On Thu, Feb 11, 2021 at 3:54 PM Hans Hagen  wrote:
>
> On 2/11/2021 2:45 PM, Mikael Sundqvist wrote:
> > Hi,
> >
> > since I already started this thread, I continue here. My metapost code
> > is still not always working, and I do not understand what is going
> > wrong. In the example below, I draw two curves of constant width (p1
> > and p2), one rotated 180 degrees around the origin. Then I draw the
> > curve (p3), constructed as follows: for each direction (phi), find the
> > point of p1 and p2 which correspond to it, and add those points. This
> > should result in a circle, and with the code I paste it does (hooray!
> > see the file minkowski-good.pdf). BUT, it seems very unstable. If I
> > change u to 0.5cm instead of 1cm, it breaks down (see
> > minkowski-bad.pdf). If I loop over more angles phi (say step 2 instead
> > of step 30), it gets wrong.
> >
> > Any ideas are welcome.
> You need help from a metapost-mathematician to answer this (ping ...
> Alan). Here is a variant that shows you what happens (keep in mind that
> ".." is not always that useful with that amount of points):
>
> \starttext
> \startMPdefinitions{doublefun}
>
> def FOO(expr u) =
>
> path p[];
>
> % This defines the reulleaux curves
> % p[0] is a "base" reulleaux curve
> path cl,cs,rl ;
> z0 = (0,6/sqrt(3)*u);
> z1 = z0 rotated 120;
> cl := (fullcircle scaled 4u) shifted z0;
> cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
> cs := (fullcircle scaled 16u) shifted z1;
> cs := cs cutafter point 1/6 along cs;
> p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs
> rotated 240) .. (cl rotated 240) .. cycle;
>
> % the first curve (darkyellow)
> % p[1] := p[0] rotated 27 shifted (-10u,2u);
> p[1] := p[0] rotated 27 shifted (-10u,2u);
> draw p1 withpen pencircle scaled 2bp withcolor darkyellow;
> % the second curve (darkblue)
> p[2] := p[1] rotated 180;
> draw p2 withpen pencircle scaled 2bp withcolor darkblue;
>
> % the minkowski sum (darkred) of the reulleaux curves p1 and p2.
> % p3 := for phi=0 step 30 until 360: ((directionpoint dir(phi) of p1)
> % shifted (directionpoint dir(phi) of p2)) .. endfor cycle;
> % draw p3 withpen pencircle scaled 2bp withcolor darkred;
>
> % for phi=0 step 30 until 360:
> % draw (directionpoint dir(phi) of p1) withpen pencircle scaled 4bp
> withcolor darkgreen;
> % draw (directionpoint dir(phi) of p2) withpen pencircle scaled 4bp
> withcolor darkmagenta;
> % endfor ;
>
> drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of p1)
> -- endfor cycle withpen pencircle scaled 1bp withcolor darkgreen;
> drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of p2)
> -- endfor cycle withpen pencircle scaled 1bp withcolor darkmagenta;
>
> drawarrow for phi=0 step 30 until 360:
>  ((directionpoint dir(phi) of p1) shifted (directionpoint dir(phi)
> of p2)) -- endfor cycle
> % .5[directionpoint dir(phi) of p1, directionpoint dir(phi) of p2]
> -- endfor cycle
> withpen pencircle scaled 1bp withcolor darkred;
>
> % We give one direction as example
> % These are merely here to show the construction of the curve
> % But they also show what is going wrong
>
> direx:=40;
>
> z11=directionpoint dir(direx) of p1;
> z22=directionpoint dir(direx) of p2;
>
> p4 = ((-u,0)--(u,0)) rotated direx;
>
> % These arrows should be tangent
> drawarrow p4 shifted z11;
> drawarrow p4 shifted z22;
> drawarrow p4 shifted (z11 shifted z22);
>
> % Draw the parallelogram.
> draw origin -- z11 dashed evenly;
> draw origin -- z22 dashed evenly;
> draw z11 -- (z11 shifted z22) dashed evenly;
> draw z22 -- (z11 shifted z22) dashed evenly;
>
> % dotlabel.top("$O$",origin);
> enddef ;
> \stopMPdefinitions
>
> \startMPpage[offset=4bp,instance=doublefun]
>  FOO(1cm);
> \stopMPpage
> \startMPpage[offset=4bp,instance=doublefun]
>  FOO(.8cm);
> \stopMPpage
> \startMPpage[offset=4bp,instance=doublefun]
>  FOO(.5cm);
> \stopMPpage
> \startMPpage[offset=4bp,instance=doublefun]
>  draw image (FOO(1/20)) scaled 5cm withpen pencircle scaled 1bp;
> \stopMPpage
> \stoptext
>
> You probably end up in the 1bp resolutions ... or something around the
> origin ... so maybe just calculate large and scale the result to what
> you want.
>
> 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 

Re: [NTG-context] Metapost: directionpoint gives unexpected point(?)

2021-02-11 Thread Hans Hagen

On 2/11/2021 2:45 PM, Mikael Sundqvist wrote:

Hi,

since I already started this thread, I continue here. My metapost code
is still not always working, and I do not understand what is going
wrong. In the example below, I draw two curves of constant width (p1
and p2), one rotated 180 degrees around the origin. Then I draw the
curve (p3), constructed as follows: for each direction (phi), find the
point of p1 and p2 which correspond to it, and add those points. This
should result in a circle, and with the code I paste it does (hooray!
see the file minkowski-good.pdf). BUT, it seems very unstable. If I
change u to 0.5cm instead of 1cm, it breaks down (see
minkowski-bad.pdf). If I loop over more angles phi (say step 2 instead
of step 30), it gets wrong.

Any ideas are welcome.
You need help from a metapost-mathematician to answer this (ping ... 
Alan). Here is a variant that shows you what happens (keep in mind that 
".." is not always that useful with that amount of points):


\starttext
\startMPdefinitions{doublefun}

def FOO(expr u) =

path p[];

% This defines the reulleaux curves
% p[0] is a "base" reulleaux curve
path cl,cs,rl ;
z0 = (0,6/sqrt(3)*u);
z1 = z0 rotated 120;
cl := (fullcircle scaled 4u) shifted z0;
cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
cs := (fullcircle scaled 16u) shifted z1;
cs := cs cutafter point 1/6 along cs;
p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs
rotated 240) .. (cl rotated 240) .. cycle;

% the first curve (darkyellow)
% p[1] := p[0] rotated 27 shifted (-10u,2u);
p[1] := p[0] rotated 27 shifted (-10u,2u);
draw p1 withpen pencircle scaled 2bp withcolor darkyellow;
% the second curve (darkblue)
p[2] := p[1] rotated 180;
draw p2 withpen pencircle scaled 2bp withcolor darkblue;

% the minkowski sum (darkred) of the reulleaux curves p1 and p2.
% p3 := for phi=0 step 30 until 360: ((directionpoint dir(phi) of p1)
% shifted (directionpoint dir(phi) of p2)) .. endfor cycle;
% draw p3 withpen pencircle scaled 2bp withcolor darkred;

% for phi=0 step 30 until 360:
% draw (directionpoint dir(phi) of p1) withpen pencircle scaled 4bp 
withcolor darkgreen;
% draw (directionpoint dir(phi) of p2) withpen pencircle scaled 4bp 
withcolor darkmagenta;

% endfor ;

drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of p1) 
-- endfor cycle withpen pencircle scaled 1bp withcolor darkgreen;
drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of p2) 
-- endfor cycle withpen pencircle scaled 1bp withcolor darkmagenta;


drawarrow for phi=0 step 30 until 360:
((directionpoint dir(phi) of p1) shifted (directionpoint dir(phi) 
of p2)) -- endfor cycle
% .5[directionpoint dir(phi) of p1, directionpoint dir(phi) of p2] 
-- endfor cycle

withpen pencircle scaled 1bp withcolor darkred;

% We give one direction as example
% These are merely here to show the construction of the curve
% But they also show what is going wrong

direx:=40;

z11=directionpoint dir(direx) of p1;
z22=directionpoint dir(direx) of p2;

p4 = ((-u,0)--(u,0)) rotated direx;

% These arrows should be tangent
drawarrow p4 shifted z11;
drawarrow p4 shifted z22;
drawarrow p4 shifted (z11 shifted z22);

% Draw the parallelogram.
draw origin -- z11 dashed evenly;
draw origin -- z22 dashed evenly;
draw z11 -- (z11 shifted z22) dashed evenly;
draw z22 -- (z11 shifted z22) dashed evenly;

% dotlabel.top("$O$",origin);
enddef ;
\stopMPdefinitions

\startMPpage[offset=4bp,instance=doublefun]
FOO(1cm);
\stopMPpage
\startMPpage[offset=4bp,instance=doublefun]
FOO(.8cm);
\stopMPpage
\startMPpage[offset=4bp,instance=doublefun]
FOO(.5cm);
\stopMPpage
\startMPpage[offset=4bp,instance=doublefun]
draw image (FOO(1/20)) scaled 5cm withpen pencircle scaled 1bp;
\stopMPpage
\stoptext

You probably end up in the 1bp resolutions ... or something around the 
origin ... so maybe just calculate large and scale the result to what 
you want.


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] Metapost: directionpoint gives unexpected point(?)

2021-02-11 Thread Mikael Sundqvist
Hi,

since I already started this thread, I continue here. My metapost code
is still not always working, and I do not understand what is going
wrong. In the example below, I draw two curves of constant width (p1
and p2), one rotated 180 degrees around the origin. Then I draw the
curve (p3), constructed as follows: for each direction (phi), find the
point of p1 and p2 which correspond to it, and add those points. This
should result in a circle, and with the code I paste it does (hooray!
see the file minkowski-good.pdf). BUT, it seems very unstable. If I
change u to 0.5cm instead of 1cm, it breaks down (see
minkowski-bad.pdf). If I loop over more angles phi (say step 2 instead
of step 30), it gets wrong.

Any ideas are welcome.

/Mikael

\starttext
\startMPpage[offset=4bp,instance=doublefun]
u:=1cm;

path p[];

% This defines the reulleaux curves
% p[0] is a "base" reulleaux curve
path cl,cs,rl ;
z0 = (0,6/sqrt(3)*u);
z1 = z0 rotated 120;
cl := (fullcircle scaled 4u) shifted z0;
cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
cs := (fullcircle scaled 16u) shifted z1;
cs := cs cutafter point 1/6 along cs;
p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs
rotated 240) .. (cl rotated 240) .. cycle;

% the first curve (darkyellow)
p[1] := p[0] rotated 27 shifted (-10u,2u);
draw p1 withpen pencircle scaled 2bp withcolor darkyellow;
% the second curve (darkblue)
p[2] := p[1] rotated 180;
draw p2 withpen pencircle scaled 2bp withcolor darkblue;

% the minkowski sum (darkred) of the reulleaux curves p1 and p2.
p3 := for phi=0 step 30 until 360: ((directionpoint dir(phi) of p1)
shifted (directionpoint dir(phi) of p2)) .. endfor cycle;
draw p3 withpen pencircle scaled 2bp withcolor darkred;

% We give one direction as example
% These are merely here to show the construction of the curve
% But they also show what is going wrong

direx:=40;

z11=directionpoint dir(direx) of p1;
z22=directionpoint dir(direx) of p2;

p4 = ((-u,0)--(u,0)) rotated direx;

% These arrows should be tangent
drawarrow p4 shifted z11;
drawarrow p4 shifted z22;
drawarrow p4 shifted (z11 shifted z22);

% Draw the parallelogram.
draw origin -- z11 dashed evenly;
draw origin -- z22 dashed evenly;
draw z11 -- (z11 shifted z22) dashed evenly;
draw z22 -- (z11 shifted z22) dashed evenly;

dotlabel.top("$O$",origin);

\stopMPpage
\stoptext

On Fri, Feb 5, 2021 at 5:51 PM Mikael Sundqvist  wrote:
>
> Hi,
>
> I was too quick to push send. This must be some rounding error.
> Changing the instance fixes the problem. Sorry for the noise.
>
> /Mikael
>
> On Fri, Feb 5, 2021 at 5:48 PM Mikael Sundqvist  wrote:
> >
> > Hi,
> >
> > I get sometimes the wrong directionpoint. In the example below it
> > works for all values of direx except between 0 and 90. If I put direx
> > to something in this interval, it seems that the point between cs and
> > cl are chosen.
> >
> > Is there a better way to construct the paths not to get this problem?
> > Or some other way out?
> >
> > /Mikael
> >
> > \starttext
> > \startMPpage[offset=3bp]
> > u:=1cm;
> > path cl,cs,rl,p[];
> > z0 = (0,6/sqrt(3)*u);
> > z1 = z0 rotated 120;
> > cs := (fullcircle scaled 16u) shifted z1;
> > cs := cs cutafter point 1/6 along cs;
> > cl := (fullcircle scaled 4u) shifted z0;
> > cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
> >
> > p[0] = cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated
> > 240) .. (cl rotated 240) .. cycle;
> >
> > draw p[0];
> >
> > drawarrow cs withcolor darkblue;
> > drawarrow cl withcolor darkred;
> >
> > direx=300;
> > z11=directionpoint dir(direx) of p[0];
> > drawarrow ((-u,0)--(u,0)) rotated direx shifted z11;
> >
> > \stopMPpage
> > \stoptext


minkowski-good.pdf
Description: Adobe PDF document


minkowski-bad.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] Metapost: directionpoint gives unexpected point(?)

2021-02-05 Thread Mikael Sundqvist
Hi,

I was too quick to push send. This must be some rounding error.
Changing the instance fixes the problem. Sorry for the noise.

/Mikael

On Fri, Feb 5, 2021 at 5:48 PM Mikael Sundqvist  wrote:
>
> Hi,
>
> I get sometimes the wrong directionpoint. In the example below it
> works for all values of direx except between 0 and 90. If I put direx
> to something in this interval, it seems that the point between cs and
> cl are chosen.
>
> Is there a better way to construct the paths not to get this problem?
> Or some other way out?
>
> /Mikael
>
> \starttext
> \startMPpage[offset=3bp]
> u:=1cm;
> path cl,cs,rl,p[];
> z0 = (0,6/sqrt(3)*u);
> z1 = z0 rotated 120;
> cs := (fullcircle scaled 16u) shifted z1;
> cs := cs cutafter point 1/6 along cs;
> cl := (fullcircle scaled 4u) shifted z0;
> cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
>
> p[0] = cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated
> 240) .. (cl rotated 240) .. cycle;
>
> draw p[0];
>
> drawarrow cs withcolor darkblue;
> drawarrow cl withcolor darkred;
>
> direx=300;
> z11=directionpoint dir(direx) of p[0];
> drawarrow ((-u,0)--(u,0)) rotated direx shifted z11;
>
> \stopMPpage
> \stoptext
___
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] Metapost: directionpoint gives unexpected point(?)

2021-02-05 Thread Mikael Sundqvist
Hi,

I get sometimes the wrong directionpoint. In the example below it
works for all values of direx except between 0 and 90. If I put direx
to something in this interval, it seems that the point between cs and
cl are chosen.

Is there a better way to construct the paths not to get this problem?
Or some other way out?

/Mikael

\starttext
\startMPpage[offset=3bp]
u:=1cm;
path cl,cs,rl,p[];
z0 = (0,6/sqrt(3)*u);
z1 = z0 rotated 120;
cs := (fullcircle scaled 16u) shifted z1;
cs := cs cutafter point 1/6 along cs;
cl := (fullcircle scaled 4u) shifted z0;
cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;

p[0] = cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated
240) .. (cl rotated 240) .. cycle;

draw p[0];

drawarrow cs withcolor darkblue;
drawarrow cl withcolor darkred;

direx=300;
z11=directionpoint dir(direx) of p[0];
drawarrow ((-u,0)--(u,0)) rotated direx shifted z11;

\stopMPpage
\stoptext
___
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] metapost graph and ConTeXt LMTX

2021-01-03 Thread Jean-Philippe Rey
Le 3 janv. 2021 à 19:21, Hans Hagen  a écrit :On 1/3/2021 7:12 PM, Jean-Philippe Rey wrote:Dear List,I have used TikZ and pgfplots for a few years and I am considering switching to metapost/metafun which appears more efficient with LMTX. I have already designed several figures with metapost/metafun and some with the help of metaobj and I am fully satisfied with the result.Alan rewrote graph in a more context way ... so, there is the m-grapph.mkiv module (I admit, not tested for a while).Thank you Hans for pointing to this module.I took a look at m-graph.mkiv and wrote the following ==\usemodule[graph]\starttext\startMPcode{graph}draw begingraph(150mm, 100mm);	gdraw "test-mpgraph.txt";	endgraph;\stopMPcode\stoptext==which fails with "error: Improper type" (see attached log file). Maybe I don't understand how to use the graph module.
-- Jean-Philippe Reyjean-philippe@centralesupelec.fr91192 Gif-sur-Yvette Cedex - FranceEmpreinte PGP : 807A 5B2C 69E4 D4B5 783A 428A 1B5E E83E 261B BF51



test-mpgraph.log
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] metapost graph and ConTeXt LMTX

2021-01-03 Thread Hans Hagen

On 1/3/2021 7:12 PM, Jean-Philippe Rey wrote:

Dear List,

I have used TikZ and pgfplots for a few years and I am considering switching to 
metapost/metafun which appears more efficient with LMTX. I have already 
designed several figures with metapost/metafun and some with the help of 
metaobj and I am fully satisfied with the result.


Alan rewrote graph in a more context way ... so, there is the 
m-grapph.mkiv module (I admit, not tested for a while).


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
___


[NTG-context] metapost graph and ConTeXt LMTX

2021-01-03 Thread Jean-Philippe Rey
Dear List,

I have used TikZ and pgfplots for a few years and I am considering switching to 
metapost/metafun which appears more efficient with LMTX. I have already 
designed several figures with metapost/metafun and some with the help of 
metaobj and I am fully satisfied with the result.

I am now trying to draw graphs with the metapost graph module, but I haven't 
been integrated to my ConTeXt LMTX document. The following example works 
perfectly well when compiled directly with metapost (from TeXlive 2020).

= mpost example =
beginfig(1)
input graph

draw begingraph(150mm, 100mm);
gdraw "test-mpgraph.txt";
endgraph;
endfig;
end
=

Here is my demo data file

 test-mpgraph.txt 
0 0
1 1
2 2
3 1
4 3
5 2
6 1
==

I tried the following to draw directly from a ConTeXt document

 LMTX example =
\starttext
\startMPcode
troffmode:=0;
prologues:=0;
input graph

draw begingraph(150mm, 100mm);
gdraw "test-mpgraph.txt";
endgraph;
\stopMPcode
\stoptext
===

I had to define troffmode and prologues, otherwise I get error messages about 
undecidable expressions and now I get an error that I don't understand (see 
attached log file).

I also tried \usemodule[graph] as documented on the wiki 
(https://wiki.contextgarden.net/MPgraph) but without success.

I guess I am doing something wrong. Could someone help me see my error?

Thanks,

-- 
Jean-Philippe Rey
jean-philippe@centralesupelec.fr
91192 Gif-sur-Yvette Cedex - France
Empreinte PGP : 807A 5B2C 69E4 D4B5 783A 428A 1B5E E83E 261B BF51


test-mpgraph.log
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] metapost boxes error

2020-05-20 Thread Aditya Mahajan

On Wed, 20 May 2020, jk...@inradius.net wrote:


Is there a different approach to use boxes.mp?

MNWE:

\startMPpage
input boxes.mp;
 boxit.bl("left");
 boxit.br("right");
 br.sw - bl.ne = (20,0);
 drawboxed(bl,br);
\stopMPpage


Move `input boxes` outside the `\startMPpage`.


\startMPdefinitions
  input boxes.mp;
\stopMPdefinitions

\starttext
\startMPpage
  boxit.bl("left");
  boxit.br("right");
  br.sw - bl.ne = (20,0);
  drawboxed(bl,br);
\stopMPpage
\stoptext


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
___


[NTG-context] metapost boxes error

2020-05-20 Thread jk...@inradius.net
Is there a different approach to use boxes.mp?

MNWE:

\startMPpage
input boxes.mp;
  boxit.bl("left");
  boxit.br("right");
  br.sw - bl.ne = (20,0);
  drawboxed(bl,br);
\stopMPpage

LOG snippets:

system  > ConTeXt  ver: 2020.04.10 19:11 MKIV beta  fmt: 2020.4.19  
int: english/english

metapost log> loading metafun, including plain.mp version 1.004 for metafun 
iv and xl
metapost log> 
metapost log> >> _dojoin
metapost log> ! Isolated expression.




___
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] METAPOST subpath rounding issue

2020-05-10 Thread Gerben Wierda

> On 10 May 2020, at 00:01, Bruce Horrocks  wrote:
> 
>> You can save extracting the xparts and yparts by using direct subtraction of 
>> pairs and comparing with (0,0) like this:
> 
> Aaaargh, no, ignore that, it's nonsense. It's amazing how you can stare at 
> something for minutes but only see the flaw the moment you press send. Sorry 
> for the noise.

Instead, I would like to thank you for thinking about it and trying to help. 
Wrestling with it (and making mistakes) is part of all that (I’ve probably made 
more than most).

G

___
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] METAPOST subpath rounding issue

2020-05-09 Thread Bruce Horrocks
> You can save extracting the xparts and yparts by using direct subtraction of 
> pairs and comparing with (0,0) like this:

Aaaargh, no, ignore that, it's nonsense. It's amazing how you can stare at 
something for minutes but only see the flaw the moment you press send. Sorry 
for the noise.

--
Bruce Horrocks
Hampshire, UK

___
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] METAPOST subpath rounding issue

2020-05-09 Thread Bruce Horrocks


> On 8 May 2020, at 13:58, Gerben Wierda  wrote:
> 
>> On 8 May 2020, at 00:46, n...@scorecrow.com wrote:
>> 
>>> On 7 May 2020, at 20:28, Gerben Wierda  wrote:
>>> 
>>> I have a METAPOST algorithm that splits a path at a certain time in two, 
>>> does something with both ends (not the ends where they were split) and then 
>>> rejoins them.
>>> 
>>> In very rare cases this crashes, because the subpath doesn’t work as 
>>> expected.
>>> 
>>>  firstPart := subpath (0,halfWayTime) of workingConn;
>>>  secondPart := subpath (halfWayTime,pathTimeLen) of workingConn;
>>> 
>>> may sometimes result in something like this:
>>> 
>>> metapost log> >> Path at line 0:
>>> metapost log> (273,-427)..controls (259.50,-427) and 
>>> (246.013335,-427)
>>> metapost log>  ..(232.520001,-427)
>>> metapost log> 
>>> metapost log> >> Path at line 0:
>>> metapost log> (232.519998,-427)..controls 
>>> (161.680001,-427) and (90.84000
>>> metapost log> 03,-427)
>>> metapost log>  ..(20,-427)
>>> 
>>> As can be seen in these (rare) cases the two calls to subpath result in a 
>>> different point resulting from both. so, when I later try to rejoin them 
>>> with & it fails:
>>> 
>>> metapost log> ! Paths don't touch; '&' will be changed to '..'.
>>> metapost log>  
>>> 
>>> Which means subpath doesn’t always exactly do what I expect it to do (and 
>>> many explanations, but not the official manual) state. Again, this is rare.
>>> 
>>> I’ve done this to work around it but I wondered if there was a better 
>>> (reliable) solution
>>> 
>>>  save cutFirstPart; path cutFirstPart; cutFirstPart := firstPart 
>>> maxcutbefore fromPicOutline;
>>>  save cutSecondPart; path cutSecondPart; cutSecondPart := secondPart 
>>> maxcutafter toPicOutline;
>>>  if ((xpart point 0 of cutSecondPart) <> (xpart point infinity of 
>>> cutFirstPart))
>>>or ((ypart point 0 of cutSecondPart) <> (ypart point infinity of 
>>> cutFirstPart)):
>>>resultConn := cutFirstPart--cutSecondPart;
>>>  else:
>>>resultConn := cutFirstPart & cutSecondPart;
>>>  fi
>> 
>> A crude test of 
>> 
>>  path pb;
>>  pb:=(5.5cm,0cm)--(5.5cm,0cm)--(10.5cm,0cm);
>>  draw pb;
>> 
>> gives no errors so why not just join using -- all the time and save the test?
> 
> Because the double exact points are also creating (different) problems in my 
> algorithm as they make the path have 'no direction' at that point (direction 
> is (0,0).

You can save extracting the xparts and yparts by using direct subtraction of 
pairs and comparing with (0,0) like this:

\starttext
\startMPcode
path cutFirstPart,cutSecondPart;

cutFirstPart := (0,0) -- (232.520001,-427);
cutSecondPart := (232.519998,-427) -- (999,-427);
%cutFirstPart := (0,0) -- (232.520001,-427);
%cutSecondPart := (232.520001,-427) -- (999,-427);

if (point infinity of cutFirstPart) - (point 0 of cutSecondPart) = (0,0) :
  label("same", (1cm,1cm))
else :
  label("different", (1cm,1cm))
fi;
\stopMPcode
\stoptext

*Except* that the example doesn't work with floats that are so close. Changing 
232.52_etc to 332.52_etc works as expected. I'm hoping that this is a "feature" 
of the parser reading in the example at a lower precision than the number of 
decimals provided. For your code, where the different values are created by 
calculation, the two pairs should be recognised as different.

--
Bruce Horrocks
Hampshire, UK

___
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] METAPOST subpath rounding issue

2020-05-08 Thread Gerben Wierda


> On 8 May 2020, at 00:46, n...@scorecrow.com wrote:
> 
> 
> 
>> On 7 May 2020, at 20:28, Gerben Wierda  wrote:
>> 
>> I have a METAPOST algorithm that splits a path at a certain time in two, 
>> does something with both ends (not the ends where they were split) and then 
>> rejoins them.
>> 
>> In very rare cases this crashes, because the subpath doesn’t work as 
>> expected.
>> 
>>  firstPart := subpath (0,halfWayTime) of workingConn;
>>  secondPart := subpath (halfWayTime,pathTimeLen) of workingConn;
>> 
>> may sometimes result in something like this:
>> 
>> metapost log> >> Path at line 0:
>> metapost log> (273,-427)..controls (259.50,-427) and 
>> (246.013335,-427)
>> metapost log>  ..(232.520001,-427)
>> metapost log> 
>> metapost log> >> Path at line 0:
>> metapost log> (232.519998,-427)..controls 
>> (161.680001,-427) and (90.84000
>> metapost log> 03,-427)
>> metapost log>  ..(20,-427)
>> 
>> As can be seen in these (rare) cases the two calls to subpath result in a 
>> different point resulting from both. so, when I later try to rejoin them 
>> with & it fails:
>> 
>> metapost log> ! Paths don't touch; '&' will be changed to '..'.
>> metapost log>  
>> 
>> Which means subpath doesn’t always exactly do what I expect it to do (and 
>> many explanations, but not the official manual) state. Again, this is rare.
>> 
>> I’ve done this to work around it but I wondered if there was a better 
>> (reliable) solution
>> 
>>  save cutFirstPart; path cutFirstPart; cutFirstPart := firstPart 
>> maxcutbefore fromPicOutline;
>>  save cutSecondPart; path cutSecondPart; cutSecondPart := secondPart 
>> maxcutafter toPicOutline;
>>  if ((xpart point 0 of cutSecondPart) <> (xpart point infinity of 
>> cutFirstPart))
>>or ((ypart point 0 of cutSecondPart) <> (ypart point infinity of 
>> cutFirstPart)):
>>resultConn := cutFirstPart--cutSecondPart;
>>  else:
>>resultConn := cutFirstPart & cutSecondPart;
>>  fi
> 
> A crude test of 
> 
>  path pb;
>  pb:=(5.5cm,0cm)--(5.5cm,0cm)--(10.5cm,0cm);
>  draw pb;
> 
> gives no errors so why not just join using -- all the time and save the test?

Because the double exact points are also creating (different) problems in my 
algorithm as they make the path have 'no direction' at that point (direction is 
(0,0).

G

> 
> --
> Bruce Horrocks
> Hampshire, UK
> 
> ___
> 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] METAPOST subpath rounding issue

2020-05-07 Thread Gerben Wierda
I have a METAPOST algorithm that splits a path at a certain time in two, does 
something with both ends (not the ends where they were split) and then rejoins 
them.

In very rare cases this crashes, because the subpath doesn’t work as expected.

  firstPart := subpath (0,halfWayTime) of workingConn;
  secondPart := subpath (halfWayTime,pathTimeLen) of workingConn;

may sometimes result in something like this:

metapost log> >> Path at line 0:
metapost log> (273,-427)..controls (259.50,-427) and 
(246.013335,-427)
metapost log>  ..(232.520001,-427)
metapost log> 
metapost log> >> Path at line 0:
metapost log> (232.519998,-427)..controls (161.680001,-427) 
and (90.84000
metapost log> 03,-427)
metapost log>  ..(20,-427)

As can be seen in these (rare) cases the two calls to subpath result in a 
different point resulting from both. so, when I later try to rejoin them with & 
it fails:

metapost log> ! Paths don't touch; '&' will be changed to '..'.
metapost log>  

Which means subpath doesn’t always exactly do what I expect it to do (and many 
explanations, but not the official manual) state. Again, this is rare.

I’ve done this to work around it but I wondered if there was a better 
(reliable) solution

  save cutFirstPart; path cutFirstPart; cutFirstPart := firstPart 
maxcutbefore fromPicOutline;
  save cutSecondPart; path cutSecondPart; cutSecondPart := secondPart 
maxcutafter toPicOutline;
  if ((xpart point 0 of cutSecondPart) <> (xpart point infinity of 
cutFirstPart))
or ((ypart point 0 of cutSecondPart) <> (ypart point infinity of 
cutFirstPart)):
resultConn := cutFirstPart--cutSecondPart;
  else:
resultConn := cutFirstPart & cutSecondPart;
  fi

G___
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] METAPOST subpath rounding issue

2020-05-07 Thread ntg


> On 7 May 2020, at 20:28, Gerben Wierda  wrote:
> 
> I have a METAPOST algorithm that splits a path at a certain time in two, does 
> something with both ends (not the ends where they were split) and then 
> rejoins them.
> 
> In very rare cases this crashes, because the subpath doesn’t work as expected.
> 
>   firstPart := subpath (0,halfWayTime) of workingConn;
>   secondPart := subpath (halfWayTime,pathTimeLen) of workingConn;
> 
> may sometimes result in something like this:
> 
> metapost log> >> Path at line 0:
> metapost log> (273,-427)..controls (259.50,-427) and 
> (246.013335,-427)
> metapost log>  ..(232.520001,-427)
> metapost log> 
> metapost log> >> Path at line 0:
> metapost log> (232.519998,-427)..controls 
> (161.680001,-427) and (90.84000
> metapost log> 03,-427)
> metapost log>  ..(20,-427)
> 
> As can be seen in these (rare) cases the two calls to subpath result in a 
> different point resulting from both. so, when I later try to rejoin them with 
> & it fails:
> 
> metapost log> ! Paths don't touch; '&' will be changed to '..'.
> metapost log>  
> 
> Which means subpath doesn’t always exactly do what I expect it to do (and 
> many explanations, but not the official manual) state. Again, this is rare.
> 
> I’ve done this to work around it but I wondered if there was a better 
> (reliable) solution
> 
>   save cutFirstPart; path cutFirstPart; cutFirstPart := firstPart 
> maxcutbefore fromPicOutline;
>   save cutSecondPart; path cutSecondPart; cutSecondPart := secondPart 
> maxcutafter toPicOutline;
>   if ((xpart point 0 of cutSecondPart) <> (xpart point infinity of 
> cutFirstPart))
> or ((ypart point 0 of cutSecondPart) <> (ypart point infinity of 
> cutFirstPart)):
> resultConn := cutFirstPart--cutSecondPart;
>   else:
> resultConn := cutFirstPart & cutSecondPart;
>   fi

A crude test of 

  path pb;
  pb:=(5.5cm,0cm)--(5.5cm,0cm)--(10.5cm,0cm);
  draw pb;

gives no errors so why not just join using -- all the time and save the test?

--
Bruce Horrocks
Hampshire, UK

___
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] METAPOST textext() eats my \pars. Was: Setting vertical spacing of lines inside a \framed[align=]

2020-04-24 Thread Gerben Wierda
> On 24 Apr 2020, at 18:40, Thomas A. Schmitz  > wrote:
> 
> 
> 
>> On 24. Apr 2020, at 18:19, Gerben Wierda > > wrote:
>> 
>> \starttext
>> 
>> \framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
>>  g=0.000,
>> b=0.000]{\switchtobodyfont[11.0pt] \setupinterlinespace[20pt] \rm 
>> [My]\\Application\\(Component)}}
>> 
>> \stoptext
>> 
>> and if I change the value to 0.6, only the first line break gets packed 
>> somewhat. But I can’t get the entire paragraph inside the frame packed. I 
>> played around with the placing of setupinterlinespace in that snippet above, 
>> but nothing really works so far.
>> 
> 
> At the end of your frame, you need an explicit \par to make the change of 
> linespacing work:
> 
> \framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
>  g=0.000,
> b=0.000]{\switchtobodyfont[11.0pt] \setupinterlinespace[14pt] \rm 
> [My]\\Application\\(Component)\par }}

Thank you, that works. (Can’t put in the images to show, as this gets my 
message over 100k)

But it turns out, I have an additional problem because I am doing this inside a 
textext() from METAPOST and that seems to strip the \pars again. Tracking 
ConTeXt:

cld > tex > f : 8 : picture pic; x:=33.000; y:=53.000; w:=133.000; 
h:=53.000;pic := ApplicationComponentLogo( w, h, (0.686,1.000,1.000), 0.200, 
1.000, (0.000,0.000,0.000), 1.000, 0.700, (0.000,0.000,0.000), 1.000, 
"\framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
 g=0.000, b=0.000]{\switchtobodyfont[11.0pt]\setupinterlinespace[11.5pt] \rm 
[My]\\Application\\(Component)\par}}\par") shifted (x, -y); draw pic;path 
AllNodeIds_idIC;  AllNodeIds_idIC := pathpart pic; pair AllNodeCenters_idIC; 
AllNodeCenters_idIC := center pic;

which looks OK (this is lmtx passing the string to ConTeXt using the lua 
context() call). The \pars are still there.

Then later, when METAPOST is at it and that same string is used to put into 
textext(), it results in:

cld > tex > w : - : \MPLIBsetNtextX{3}{\framed 
[align=flushright,frame=on,offset=none,width=106.400bp]{\colored [r=0.000, 
g=0.000, b=0.000]{\switchtobodyfont [11.0pt]\setupinterlinespace [11.5pt] \rm 
[My]\\Application\\(Component)}}}


Minimal example:

\enabletrackers[context.trace]
\starttext

% Works OK:
\framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
 g=0.000,
b=0.000]{\switchtobodyfont[11.0pt]\setupinterlinespace[11.5pt] \rm 
[My]\\Application\\(Component)\par}}

% Doesn’t work:
\startMPpage[instance=doublefun]
draw 
textext("\framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
 g=0.000, b=0.000]{\switchtobodyfont[11.0pt]\setupinterlinespace[11.5pt] \rm 
[My]\\Application\\(Component)\par}}\par");
\stopMPpage


\stoptext

So, now I’m looking for a way to prevent textext() to eat my \pars

G

___
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] METAPOST textext() eats my \pars. Was: Setting vertical spacing of lines inside a \framed[align=]

2020-04-24 Thread Gerben Wierda


> On 24 Apr 2020, at 18:40, Thomas A. Schmitz  > wrote:
> 
> 
> 
>> On 24. Apr 2020, at 18:19, Gerben Wierda > > wrote:
>> 
>> \starttext
>> 
>> \framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
>>  g=0.000,
>> b=0.000]{\switchtobodyfont[11.0pt] \setupinterlinespace[20pt] \rm 
>> [My]\\Application\\(Component)}}
>> 
>> \stoptext
>> 
>> and if I change the value to 0.6, only the first line break gets packed 
>> somewhat. But I can’t get the entire paragraph inside the frame packed. I 
>> played around with the placing of setupinterlinespace in that snippet above, 
>> but nothing really works so far.
>> 
> 
> At the end of your frame, you need an explicit \par to make the change of 
> linespacing work:
> 
> \framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
>  g=0.000,
> b=0.000]{\switchtobodyfont[11.0pt] \setupinterlinespace[14pt] \rm 
> [My]\\Application\\(Component)\par }}

Thank you, that works: 



But it turns out, I have an additional problem because I am doing this inside a 
textext() from METAPOST and that seems to strip the \pars again. Tracking 
ConTeXt:

cld > tex > f : 8 : picture pic; x:=33.000; y:=53.000; w:=133.000; 
h:=53.000;pic := ApplicationComponentLogo( w, h, (0.686,1.000,1.000), 0.200, 
1.000, (0.000,0.000,0.000), 1.000, 0.700, (0.000,0.000,0.000), 1.000, 
"\framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
 g=0.000, b=0.000]{\switchtobodyfont[11.0pt]\setupinterlinespace[11.5pt] \rm 
[My]\\Application\\(Component)\par}}\par") shifted (x, -y); draw pic;path 
AllNodeIds_idIC;  AllNodeIds_idIC := pathpart pic; pair AllNodeCenters_idIC; 
AllNodeCenters_idIC := center pic;

which looks OK (this is lmtx passing the string to ConTeXt using the lua 
context() call). The \pars are still there.

Then later, when METAPOST is at it and that same string is used to put into 
textext(), it results in:

cld > tex > w : - : \MPLIBsetNtextX{3}{\framed 
[align=flushright,frame=on,offset=none,width=106.400bp]{\colored [r=0.000, 
g=0.000, b=0.000]{\switchtobodyfont [11.0pt]\setupinterlinespace [11.5pt] \rm 
[My]\\Application\\(Component)}}}

The result of which is



Minimal example:

\enabletrackers[context.trace]
\starttext

% Works OK:
\framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
 g=0.000,
b=0.000]{\switchtobodyfont[11.0pt]\setupinterlinespace[11.5pt] \rm 
[My]\\Application\\(Component)\par}}

% Doesn’t work:
\startMPpage[instance=doublefun]
draw 
textext("\framed[align=flushright,frame=on,offset=none,width=106.400bp]{\colored[r=0.000,
 g=0.000, b=0.000]{\switchtobodyfont[11.0pt]\setupinterlinespace[11.5pt] \rm 
[My]\\Application\\(Component)\par}}\par");
\stopMPpage


\stoptext

So, now I’m looking for a way to prevent textext() to eat my \pars

G___
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] METAPOST: How do I get this 'max' cutafter to work?

2020-04-22 Thread Gerben Wierda
> On 22 Apr 2020, at 09:30, Taco Hoekwater  wrote:
> 
> Hi,
> 
>> On 21 Apr 2020, at 17:52, Gerben Wierda  wrote:
>> 
>>> pair a ; a := arrowHead intersection_point connection ;
> 
> Hans’ example also works with “intersectionpoint”: the differences between 
> intersectionpoint
> and intersection_point are minimal except if there is no intersection at all.
> 
> The trick is that Hans does not use cutafter. cutafter is designed to cut off 
> as little as 
> possible, it is a cutbefore on both paths reversed. So, uses the last 
> intersection point of 
> the paths, and in this case it will therefore use the top of the arrowhead. 
> 
> In contrast, intersectionpoint finds the first intersection on the 
> non-reversed paths, which 
> is the base of the arrowhead.
> 
> Alternatively (in this case), you could move the arrowhead up a tiny amount, 
> so that there is 
> only one intersection between the connection and arrowHead.

In fact I did something like this, except that I first shortened the line path 
so it ends in the middle of the triangle before doing a cutafter (twice in both 
directions and taking the one which cuts the most). This works reliably.

I gave up on another approach (which repeatedly cut a little bit from the path 
until it wasn’t intersecting anymore, then taking the one form thelast 
successful intersection)  as I also have paths that connect a path-cycle to 
itself. A ‘cut until it just doesn’t intersect anymore' would eat up the entire 
path in that case until only a single point is left.

G

> 
> Best wishes,
> Taco
> ___
> 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
___


Re: [NTG-context] METAPOST: How do I get this 'max' cutafter to work?

2020-04-22 Thread luigi scarso
On Wed, Apr 22, 2020 at 9:30 AM Taco Hoekwater  wrote:

>
> In contrast, intersectionpoint finds the first intersection on the
> non-reversed paths, which
> is the base of the arrowhead.
>
>
IIrc ,  it's the first in shuffle order

@ Incidentally, if the given cubics intersect more than once, the process
just sketched will not necessarily find the lexicographically smallest pair
$(t_1,t_2)$. The solution actually obtained will be smallest in ``shuffled
order''; i.e., if $t_1=(.a_1a_2\ldots a_{16})_2$ and
$t_2=(.b_1b_2\ldots b_{16})_2$, then we will minimize
$a_1b_1a_2b_2\ldots a_{16}b_{16}$, not
$a_1a_2\ldots a_{16}b_1b_2\ldots b_{16}$.
Shuffled order agrees with lexicographic order if all pairs of solutions
$(t_1,t_2)$ and $(t_1',t_2')$ have the property that $t_1___
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] METAPOST: How do I get this 'max' cutafter to work?

2020-04-22 Thread Taco Hoekwater
Hi,

> On 21 Apr 2020, at 17:52, Gerben Wierda  wrote:
> 
>> pair a ; a := arrowHead intersection_point connection ;

Hans’ example also works with “intersectionpoint”: the differences between 
intersectionpoint
and intersection_point are minimal except if there is no intersection at all.

The trick is that Hans does not use cutafter. cutafter is designed to cut off 
as little as 
possible, it is a cutbefore on both paths reversed. So, uses the last 
intersection point of 
the paths, and in this case it will therefore use the top of the arrowhead. 

In contrast, intersectionpoint finds the first intersection on the non-reversed 
paths, which 
is the base of the arrowhead.

Alternatively (in this case), you could move the arrowhead up a tiny amount, so 
that there is 
only one intersection between the connection and arrowHead.

Best wishes,
Taco
___
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] METAPOST: How do I get this 'max' cutafter to work?

2020-04-21 Thread Hans Hagen

On 4/21/2020 5:52 PM, Gerben Wierda wrote:

Pretty deep into MP now. Even looked up the reference in John Hobby’s 
manual to the METAFONT book, but that reference did not help.
in the end it all has to do with accuracy and rounding ... the 
intersection_point trickery is probably less sensitive for that


but it's so long ago that i mp-tool was written that that part of my 
mind probably has been overwritten, obscured or wiped


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] METAPOST: How do I get this 'max' cutafter to work?

2020-04-21 Thread Gerben Wierda


> On 21 Apr 2020, at 14:41, Hans Hagen  wrote:
> 
> On 4/21/2020 1:29 PM, Gerben Wierda wrote:
[snip]
> 
> \startMPpage[instance=doublefun]
> 
> path arrowHead;
> arrowHead :=
>(542,-77.000186920166016)..controls 
> (545.37,-77.000186920166016) and
>(548.63,-77.000186920166016) 
> ..(552,-77.000186920166016)..controls
>(550.37,-73.666853586832687) and
>(548.63,-70.333520253499344) 
> ..(547,-67.000186920166016)..controls
>(545.37,-70.333520253499344) and
>(543.63,-73.666853586832687) ..cycle;
> 
> path connection;
> connection :=
>  (420.4959106445,-367)..controls (420.66670256708773,-367) and
>  (421.55543111,-367) ..(422.0851913427,-367)..controls
>  (425.3917170194,-367) and (428.698242696,-367)
>  ..(432.0047683727,-367)..controls (442.0015894574,-367) and
>  (451.9984105426,-367) ..(461.9952316273,-367)..controls
>  (464.76142345324098,-367) and (467,-364.76142382108867)
>  ..(467,-361.9997656772)..controls (467,-293.218926) and
>  (467,-226.781074) ..(467,-158.0002343228)..controls
>  (467,-155.23857623850762) and (469.23857634039018,-153)
>  ..(472.0014901161,-153)..controls (495.3338300389,-153) and
>  (518.6661699617,-153) ..(541.9985098839,-153)..controls
>  (544.76142368504975,-153) and (547,-150.76142367339932)
>  ..(547,-147.9983662815)..controls (547,-125.9994554271) and
>  (547,-104.0005445727) ..(547,-82.00163371837)..controls
>  (547,-78.68047283764) and (547,-75.35931195691)
>  ..(547,-72.03815107618)..controls (547,-70.98183460417) and
>  (547,-68.666792551813217) ..(547,-67.000186920166016);
> 
> pair a ; a := arrowHead intersection_point connection ;
> 
> draw connection cutafter arrowHead   withcolor red   withpen 
> pencircle scaled 2mm ;
> draw connection cutafter (reverse arrowHead) withcolor green withpen 
> pencircle scaled 1mm ;
> 
> draw arrowHead;
> 
> draw a withcolor blue withpen pencircle scaled 3mm ;
> 
> currentpicture := currentpicture shifted (-bbwidth(currentpicture), 0) ;
> 
> draw connection cutafter a ;
> 
> draw arrowHead;
> 
> 
> \stopMPpage

Hi Hans, thanks.

I am completely in the dark why your intersection_point works (and thus if it 
will keep working in all circumstances).

I’d like to understand what is going on here. Why does intersection_point work 
where cutafter does not? After all, both are based on the same 
intersectiontimes primitive to find the intersection and they should thus find 
the same one: the ’perfect’ intersection which is the end point of the path 
that is to be cut. 

I’d like to understand this, because otherwise I might run into the same 
problem again later with slightly different paths involved. The first algo that 
I was using worked fine in most cases, as well, then I created one that worked 
with paths with ‘internal spikes’ and now I run into this where two comparable 
situations behaved differently and my question copied the one that didn’t work. 
And while this example from you works, I need to have something that is 100% 
reliable.

What METAPOST comes with is:

path cuttings;  % what got cut off

tertiarydef a cutbefore b =  % tries to cut as little as possible
  begingroup save t;
  (t, whatever) = a intersectiontimes b;
  if t<0:
cuttings:=point 0 of a;
a
  else: cuttings:= subpath (0,t) of a;
subpath (t,length a) of a
  fi
  endgroup
enddef;

tertiarydef a cutafter b =
  reverse (reverse a  cutbefore  b)
  hide(cuttings:=reverse cuttings)
enddef;

secondarydef p intersectionpoint q =
 begingroup save x_,y_; (x_,y_)=p intersectiontimes q;
 if x_<0: errmessage("The paths don't intersect"); origin
 else: .5[point x_ of p, point y_ of q] fi endgroup
enddef;

What is in MetaFun is:

boolean intersection_found ;

secondarydef p intersection_point q =
begingroup
save x_, y_ ;
(x_,y_) = p intersectiontimes q ;
if x_< 0 :
intersection_found := false ;
center p % origin
else :
intersection_found := true ;
.5[point x_ of p, point y_ of q]
fi
endgroup
enddef ;

The thing I can think of is cutting a bit, trying if it still intersects and if 
it does repeat and if it doesn’t take the previous result. I can’t rely on the 
length of cuttings being 0, because this is true in the case of no intersection 
(cuttings equals (0,0)) as well as a ‘perfect’ intersection at the end of the 
path (cuttings is the point at the end of the path). I could rely on cuttings 
being the path (0,0) but how do I compare paths (and not pairs)?

G 

Pretty deep into MP now. Even looked up the reference in John Hobby’s manual to 
the METAFONT book, but that reference did not help.


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 

Re: [NTG-context] METAPOST: How do I get this 'max' cutafter to work?

2020-04-21 Thread Hans Hagen

On 4/21/2020 1:29 PM, Gerben Wierda wrote:
I have these two paths, but cutting doesn’t work because the path to be 
cut takes the wrong intersection regardless of how I direct the path to 
be cut after (reverse or not).


The path to cut after is a triangle with the base horizontal and the 
path to cut is a vertical line. The top of the triangle is the endpoint 
of the line and is selected as intersection by cutafter. This happens 
also if I reverse the triangle path, strangely enough. I have an 
alternative cutting algorithm, but that cuts as long as the length of 
cuttings is not 0, which is the case at the top too, so it won’t cut 
further.


I need a reliable algorithm to make a ‘maximum cutafter’. What might be 
a good approach?


G

path arrowHead;
arrowHead :=
   (542,-77.000186920166016)..controls 
(545.37,-77.000186920166016) and 
(548.63,-77.000186920166016)
   ..(552,-77.000186920166016)..controls 
(550.37,-73.666853586832687)

   and (548.63,-70.333520253499344)
   ..(547,-67.000186920166016)..controls 
(545.37,-70.333520253499344)

   and (543.63,-73.666853586832687)
   ..cycle;

path connection;
connection :=
   (420.4959106445,-367)..controls (420.66670256708773,-367) and 
(421.55543111,-367)
   ..(422.0851913427,-367)..controls (425.3917170194,-367) and 
(428.698242696,-367)
   ..(432.0047683727,-367)..controls (442.0015894574,-367) and 
(451.9984105426,-367)
   ..(461.9952316273,-367)..controls (464.76142345324098,-367) and 
(467,-364.76142382108867)
   ..(467,-361.9997656772)..controls (467,-293.218926) and 
(467,-226.781074)
   ..(467,-158.0002343228)..controls (467,-155.23857623850762) and 
(469.23857634039018,-153)
   ..(472.0014901161,-153)..controls (495.3338300389,-153) and 
(518.6661699617,-153)
   ..(541.9985098839,-153)..controls (544.76142368504975,-153) and 
(547,-150.76142367339932)
   ..(547,-147.9983662815)..controls (547,-125.9994554271) and 
(547,-104.0005445727)
   ..(547,-82.00163371837)..controls (547,-78.68047283764) and 
(547,-75.35931195691)
   ..(547,-72.03815107618)..controls (547,-70.98183460417) and 
(547,-68.666792551813217)

   ..(547,-67.000186920166016);

show connection cutafter arrowHead;
show connection cutafter (reverse arrowHead);


\startMPpage[instance=doublefun]

path arrowHead;
arrowHead :=
(542,-77.000186920166016)..controls 
(545.37,-77.000186920166016) and
(548.63,-77.000186920166016) 
..(552,-77.000186920166016)..controls

(550.37,-73.666853586832687) and
(548.63,-70.333520253499344) 
..(547,-67.000186920166016)..controls

(545.37,-70.333520253499344) and
(543.63,-73.666853586832687) ..cycle;

path connection;
connection :=
  (420.4959106445,-367)..controls (420.66670256708773,-367) and
  (421.55543111,-367) ..(422.0851913427,-367)..controls
  (425.3917170194,-367) and (428.698242696,-367)
  ..(432.0047683727,-367)..controls (442.0015894574,-367) and
  (451.9984105426,-367) ..(461.9952316273,-367)..controls
  (464.76142345324098,-367) and (467,-364.76142382108867)
  ..(467,-361.9997656772)..controls (467,-293.218926) and
  (467,-226.781074) ..(467,-158.0002343228)..controls
  (467,-155.23857623850762) and (469.23857634039018,-153)
  ..(472.0014901161,-153)..controls (495.3338300389,-153) and
  (518.6661699617,-153) ..(541.9985098839,-153)..controls
  (544.76142368504975,-153) and (547,-150.76142367339932)
  ..(547,-147.9983662815)..controls (547,-125.9994554271) and
  (547,-104.0005445727) ..(547,-82.00163371837)..controls
  (547,-78.68047283764) and (547,-75.35931195691)
  ..(547,-72.03815107618)..controls (547,-70.98183460417) and
  (547,-68.666792551813217) ..(547,-67.000186920166016);

pair a ; a := arrowHead intersection_point connection ;

draw connection cutafter arrowHead   withcolor red   withpen 
pencircle scaled 2mm ;
draw connection cutafter (reverse arrowHead) withcolor green withpen 
pencircle scaled 1mm ;


draw arrowHead;

draw a withcolor blue withpen pencircle scaled 3mm ;

currentpicture := currentpicture shifted (-bbwidth(currentpicture), 0) ;

draw connection cutafter a ;

draw arrowHead;


\stopMPpage

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

[NTG-context] METAPOST: How do I get this 'max' cutafter to work?

2020-04-21 Thread Gerben Wierda
I have these two paths, but cutting doesn’t work because the path to be cut 
takes the wrong intersection regardless of how I direct the path to be cut 
after (reverse or not).

The path to cut after is a triangle with the base horizontal and the path to 
cut is a vertical line. The top of the triangle is the endpoint of the line and 
is selected as intersection by cutafter. This happens also if I reverse the 
triangle path, strangely enough. I have an alternative cutting algorithm, but 
that cuts as long as the length of cuttings is not 0, which is the case at the 
top too, so it won’t cut further.

I need a reliable algorithm to make a ‘maximum cutafter’. What might be a good 
approach?

G

path arrowHead;
arrowHead :=
  (542,-77.000186920166016)..controls (545.37,-77.000186920166016) 
and (548.63,-77.000186920166016)
  ..(552,-77.000186920166016)..controls (550.37,-73.666853586832687)
  and (548.63,-70.333520253499344)
  ..(547,-67.000186920166016)..controls (545.37,-70.333520253499344)
  and (543.63,-73.666853586832687)
  ..cycle;

path connection;
connection :=
  (420.4959106445,-367)..controls (420.66670256708773,-367) and 
(421.55543111,-367)
  ..(422.0851913427,-367)..controls (425.3917170194,-367) and 
(428.698242696,-367)
  ..(432.0047683727,-367)..controls (442.0015894574,-367) and 
(451.9984105426,-367)
  ..(461.9952316273,-367)..controls (464.76142345324098,-367) and 
(467,-364.76142382108867)
  ..(467,-361.9997656772)..controls (467,-293.218926) and 
(467,-226.781074)
  ..(467,-158.0002343228)..controls (467,-155.23857623850762) and 
(469.23857634039018,-153)
  ..(472.0014901161,-153)..controls (495.3338300389,-153) and 
(518.6661699617,-153)
  ..(541.9985098839,-153)..controls (544.76142368504975,-153) and 
(547,-150.76142367339932)
  ..(547,-147.9983662815)..controls (547,-125.9994554271) and 
(547,-104.0005445727)
  ..(547,-82.00163371837)..controls (547,-78.68047283764) and 
(547,-75.35931195691)
  ..(547,-72.03815107618)..controls (547,-70.98183460417) and 
(547,-68.666792551813217)
  ..(547,-67.000186920166016);

show connection cutafter arrowHead;
show connection cutafter (reverse arrowHead);


___
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] METAPOST/MetaFun withtransparency doesn't accept my pair primary argument, what am I doing wrong?

2020-04-10 Thread Gerben Wierda
As I only use one transparency method anyway I could also fix this by passing a 
numeric instead of a pair and use the standard withtransparency (I don’t like 
overriding a standard MetaFun method, one never knows what might break in 
future updates).

vardef Foo( expr w, h, fillColor, fillTransparency) =
  show "FOO:", w, h, fillColor, fillTransparency;
  save pic; picture pic;
  save circ; path circ;
  circ := (fullcircle xyscaled (h,h));
  pic := image (
fill (circ shifted (w-h/2,-h/2)) withcolor fillColor withtransparency 
(1,fillTransparency);
  );
  pic
enddef;

picture pic;
pic := Foo( 150, 50, (0.686,1.000,1.000), 0.5);
draw pic;
\stopMPpage
\stoptext


> On 9 Apr 2020, at 18:06, Hans Hagen  wrote:
> 
> On 4/9/2020 4:58 PM, Gerben Wierda wrote:
>> \starttext
>> \startMPpage[instance=doublefun]
>> vardef Foo( expr w, h, fillColor, fillTransparency) =
>>   show "FOO:", w, h, fillColor, fillTransparency;
>>   save pic; picture pic;
>>   save circ; path circ;
>>   circ := (fullcircle xyscaled (h,h));
>>   pic := image (
>> fill (circ shifted (w-h/2,-h/2)) withcolor fillColor withtransparency 
>> fillTransparency;
>>   );
>>   pic
>> enddef;
>> pic := Foo( 150, 50, (0.686,1.000,1.000), (1,1.000));
>> draw pic;
>> \stopMPpage
>> \stoptext
> 
> Maybe this definition is better then but I need to test it more
> 
> \starttext
> \startMPpage[instance=doublefun]
> 
> def withtransparency expr t =
>if pair t :
>withprescript "tr_alternative="  & decimal 
> transparency_alternative_to_number(xpart t)
>withprescript "tr_transparency=" & decimal ypart t
>else :
>mfun_with_transparency (transparency_alternative_to_number(t))
>fi
> enddef ;
> 
> def mfun_with_transparency (expr a) expr t =
>withprescript "tr_alternative="  & decimal a
>withprescript "tr_transparency=" & decimal t
> enddef ;
> 
> vardef Foo ( expr w, h, fillColor, fillTransparency) =
>  image (
>fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
>withcolor fillColor
>withtransparency fillTransparency
>;
>  )
> enddef;
> 
> vardef FooX ( expr w, h, fillColor) =
>  image (
>fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
>withcolor fillColor
>withtransparency (normaltransparent, .5)
>;
>  )
> enddef;
> 
> vardef FooY ( expr w, h, fillColor) =
>  image (
>fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
>withcolor fillColor
>withtransparency normaltransparent .5
>;
>  )
> enddef;
> 
> draw Foo  ( 350, 50, (0.5,1,0), (1,.5));
> draw FooX ( 250, 50, (1,0.5,1));
> draw FooY ( 150, 50, (1,1,0.5));
> 
> \stopMPpage
> \stoptext
> 
> 
> -- 
> 
> -
>  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] METAPOST/MetaFun withtransparency doesn't accept my pair primary argument, what am I doing wrong?

2020-04-09 Thread Hans Hagen

On 4/9/2020 4:58 PM, Gerben Wierda wrote:

\starttext
\startMPpage[instance=doublefun]

vardef Foo( expr w, h, fillColor, fillTransparency) =
   show "FOO:", w, h, fillColor, fillTransparency;
   save pic; picture pic;
   save circ; path circ;
   circ := (fullcircle xyscaled (h,h));
   pic := image (
     fill (circ shifted (w-h/2,-h/2)) withcolor fillColor 
withtransparency fillTransparency;

   );
   pic
enddef;

pic := Foo( 150, 50, (0.686,1.000,1.000), (1,1.000));
draw pic;
\stopMPpage
\stoptext


Maybe this definition is better then but I need to test it more

\starttext
\startMPpage[instance=doublefun]

def withtransparency expr t =
if pair t :
withprescript "tr_alternative="  & decimal 
transparency_alternative_to_number(xpart t)

withprescript "tr_transparency=" & decimal ypart t
else :
mfun_with_transparency (transparency_alternative_to_number(t))
fi
enddef ;

def mfun_with_transparency (expr a) expr t =
withprescript "tr_alternative="  & decimal a
withprescript "tr_transparency=" & decimal t
enddef ;

vardef Foo ( expr w, h, fillColor, fillTransparency) =
  image (
fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
withcolor fillColor
withtransparency fillTransparency
;
  )
enddef;

vardef FooX ( expr w, h, fillColor) =
  image (
fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
withcolor fillColor
withtransparency (normaltransparent, .5)
;
  )
enddef;

vardef FooY ( expr w, h, fillColor) =
  image (
fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
withcolor fillColor
withtransparency normaltransparent .5
;
  )
enddef;

draw Foo  ( 350, 50, (0.5,1,0), (1,.5));
draw FooX ( 250, 50, (1,0.5,1));
draw FooY ( 150, 50, (1,1,0.5));

\stopMPpage
\stoptext


--

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


[NTG-context] METAPOST/MetaFun withtransparency doesn't accept my pair primary argument, what am I doing wrong?

2020-04-09 Thread Gerben Wierda
I have refactored my code to use withtransparency and separate parameters for 
colors, sizes, transparency, etc. But I’m running into a problem. The 
fillTransparency parameter is a pair primary (as can be seen from the show 
command)

Here is a pretty minimum example (in reality there are multiple colors and 
transparencies passed on):

\starttext
\startMPpage[instance=doublefun]

vardef Foo( expr w, h, fillColor, fillTransparency) =
  show "FOO:", w, h, fillColor, fillTransparency;
  save pic; picture pic;
  save circ; path circ;
  circ := (fullcircle xyscaled (h,h));
  pic := image (
fill (circ shifted (w-h/2,-h/2)) withcolor fillColor withtransparency 
fillTransparency;
  );
  pic
enddef;

pic := Foo( 150, 50, (0.686,1.000,1.000), (1,1.000));
draw pic;
\stopMPpage
\stoptext

and the result is:

metapost log> >> "FOO:"
metapost log> >> 150
metapost log> >> 50
metapost log> >> (0.68605,1,1)
metapost log> >> (1,1)
metapost log> ! Missing argument to withtransparency.
metapost log>  
metapost log>((1,1))
metapost log>  ...005,1,1))withtransparency((1,1))
metapost log>   ;
metapost log> image->...ture;currentpicture:=nullpicture;(TEXT3)
metapost log>   
;currentpicture.if.str(SUF...
metapost log> 
metapost log> Foo->...)withcolor(EXPR4)withtransparency(EXPR5);)
metapost log>   
;pic.endgroup
metapost log> <*> ...o( 150, 50, (0.686,1.000,1.000), (1,1.000))
metapost log>   ; draw pic; 
;

What am I doing wrong here?

Thanks,

G

PS. Given the complaint about asking both here and on tex.stackexchange, which 
of the two is the best place?___
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] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Gerben Wierda
Maybe a nice little explanation (educational with good examples) of ‘how to use 
pass by reference’ and ‘building and using complex data structures’ would be 
useful for people. Say, some ‘patterns’.

G  

> On 16 Mar 2020, at 10:38, Hans Hagen  wrote:
> 
> that said, after muy share of mp programming i would not have thought about 
> the text y as pass by reference, also because it's only true for these pseudo 
> arrays (maybe suffixes also work)

___
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] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Gerben Wierda


> On 16 Mar 2020, at 10:23, Taco Hoekwater  wrote:
> 
> 
> 
>> On 16 Mar 2020, at 10:10, Taco Hoekwater  wrote:
>> 
>> 
>> 
>>> On 16 Mar 2020, at 09:53, Gerben Wierda  wrote:
>>> 
>>> Hola! So, the arguments passed to macros are by reference and not by value? 
>>> I could have known of course, they are simple expansions, but I’d like to 
>>> be sure. IfI assign to a variable inside a vardef macro and that variable 
>>> is not ’save’d I’m changing the original?
>> 
>> Yes. (A simple test would have confirmed that)
> 
> Oops, sorry, no! I was wrong on that… it must be too early for me.

Coffee! Thanks anyway, Taco, your help is really appreciated.

> 
>  vardef Foo(text y) = 
>scantokens(y&":=5”);
>  enddef;
>  Foo("x");
> 
> This would work, but that is weird.

Which is somewhat intuitive to parse as a human. I understand it as that after 
the last statement x has the value 5.

> This also works, and that is why
> I had the erroneous memory that it would work always:
> 
>  vardef Foo(expr a)(text y) = 
>y[a] := 5;
>  enddef;
>  numeric foo[]; 
>  foo[1] = 6;
>  Foo(1,foo);

This was initially complete gobbledegook to me. But I now think that after the 
last statement foo[1] equals 5. Very weird/counterintuitive that y[a] := 5 
works here without the use of scantokens. The first one is less weird to me 
because scantokens actually calls the METAPOST parser on a string as if read 
from a file.

> or you could use global variables, of course.
> 
> Main point: Metapost is not an easy language to grasp. If you want to
> really understand how it works, you should study the Metafont book by DEK.

I actually have that book and did a try small bit of METAFONT long, long ago to 
create a logo in it. Maybe that explains things better. (Unearthing the book 
for later use…)

> As you can clearly see, even experienced users are likely to make mistakes.

The main problem with all of this (ConTeXt, METAPOST, etc.) remains the 
learning curve and the lack of good and up-to-date educational materials. I.e. 
the METAPOST manual is terse, probably because it relies on people 
understanding the background that is in the METAFONT book.

And, if one is used to thinking in terms of functional programming, all that 
‘expansion’ stuff (‘replacement’  programming?) is very counterintuitive for 
me. Lua then adds a functional model to the mix (or I think it does). Very hard 
to make progress. I learned Python in a day and produced a complex program in a 
matter of weeks. This is far less easy. And not being able so far to see what 
intermediate results lea to errors adds to the slow going.

I.e., the whole chapter on vardef in the METAFONT book is 

G

> 
> 
> Best wishes,
> Taco
> 
> 
> 
> 
> ___
> 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
___


Re: [NTG-context] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Hans Hagen

On 3/16/2020 10:23 AM, Taco Hoekwater wrote:




On 16 Mar 2020, at 10:10, Taco Hoekwater  wrote:




On 16 Mar 2020, at 09:53, Gerben Wierda  wrote:

Hola! So, the arguments passed to macros are by reference and not by value? I 
could have known of course, they are simple expansions, but I’d like to be 
sure. IfI assign to a variable inside a vardef macro and that variable is not 
’save’d I’m changing the original?


Yes. (A simple test would have confirmed that)


Oops, sorry, no! I was wrong on that… it must be too early for me.

   vardef Foo(text y) =
 scantokens(y&":=5”);
   enddef;
   Foo("x");

This would work, but that is weird. This also works, and that is why
I had the erroneous memory that it would work always:

   vardef Foo(expr a)(text y) =
 y[a] := 5;
   enddef;
   numeric foo[];
   foo[1] = 6;
   Foo(1,foo);

or you could use global variables, of course.

Main point: Metapost is not an easy language to grasp. If you want to
really understand how it works, you should study the Metafont book by DEK. > As you can clearly see, even experienced users are likely to make 

mistakes.
it's the mixture of delayed parsing and expansion and ... no other 
language like that i guess (which at the same time is its charm)


passing "text y" is (i think) not that that far from the scantokens 
(running over already tokenized vs running over a string while 
tokenizing it ... but these input models (are we in scanning file input, 
string input, tokenlist) can be kind of confusing


that said, after muy share of mp programming i would not have thought 
about the text y as pass by reference, also because it's only true for 
these pseudo arrays (maybe suffixes also work)


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] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Taco Hoekwater


> On 16 Mar 2020, at 10:10, Taco Hoekwater  wrote:
> 
> 
> 
>> On 16 Mar 2020, at 09:53, Gerben Wierda  wrote:
>> 
>> Hola! So, the arguments passed to macros are by reference and not by value? 
>> I could have known of course, they are simple expansions, but I’d like to be 
>> sure. IfI assign to a variable inside a vardef macro and that variable is 
>> not ’save’d I’m changing the original?
> 
> Yes. (A simple test would have confirmed that)

Oops, sorry, no! I was wrong on that… it must be too early for me.

  vardef Foo(text y) = 
scantokens(y&":=5”);
  enddef;
  Foo("x");

This would work, but that is weird. This also works, and that is why
I had the erroneous memory that it would work always:

  vardef Foo(expr a)(text y) = 
y[a] := 5;
  enddef;
  numeric foo[]; 
  foo[1] = 6;
  Foo(1,foo);

or you could use global variables, of course.

Main point: Metapost is not an easy language to grasp. If you want to
really understand how it works, you should study the Metafont book by DEK.
As you can clearly see, even experienced users are likely to make mistakes.


Best wishes,
Taco




___
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] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Taco Hoekwater


> On 16 Mar 2020, at 09:53, Gerben Wierda  wrote:
> 
> Hola! So, the arguments passed to macros are by reference and not by value? I 
> could have known of course, they are simple expansions, but I’d like to be 
> sure. IfI assign to a variable inside a vardef macro and that variable is not 
> ’save’d I’m changing the original?

Yes. (A simple test would have confirmed that)

Taco


___
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] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Gerben Wierda
Hola! So, the arguments passed to macros are by reference and not by value? I 
could have known of course, they are simple expansions, but I’d like to be 
sure. IfI assign to a variable inside a vardef macro and that variable is not 
’save’d I’m changing the original?

G

> On 16 Mar 2020, at 09:31, Taco Hoekwater  wrote:
> 
> 
> 
>> On 15 Mar 2020, at 11:22, Gerben Wierda  wrote:
>> 
>> I would like a vardef macro to return the pair of a picture and a bounding 
>> box. I don't want to use the setbound operator, because as soon as I do 
>> that, I cannot access the components of the picture anymore with pathpart.
>> 
>> I found metapost vardef returning multiple values on StackExchange but that 
>> is about returning multiple values of the same numeric type. Is it possible 
>> to have vardef return a set of (picture, path) or (picture, picture) in some 
>> way? If not, I need to make two vardef macros for each result type.
> 
> Sure, using that same endgroup,begingroup trick. But since there is no 
> multi-assignment in metapost that doesn’t you help much.
> Either two separate vardefs or passing the to-be-assigned variable(s) as an 
> extra argument(s) are generally more practical.
> 
> Best wishes,
> Taco
> 
> 
> 
> ___
> 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
___


Re: [NTG-context] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-16 Thread Taco Hoekwater


> On 15 Mar 2020, at 11:22, Gerben Wierda  wrote:
> 
> I would like a vardef macro to return the pair of a picture and a bounding 
> box. I don't want to use the setbound operator, because as soon as I do that, 
> I cannot access the components of the picture anymore with pathpart.
> 
> I found metapost vardef returning multiple values on StackExchange but that 
> is about returning multiple values of the same numeric type. Is it possible 
> to have vardef return a set of (picture, path) or (picture, picture) in some 
> way? If not, I need to make two vardef macros for each result type.

Sure, using that same endgroup,begingroup trick. But since there is no 
multi-assignment in metapost that doesn’t you help much.
Either two separate vardefs or passing the to-be-assigned variable(s) as an 
extra argument(s) are generally more practical.

Best wishes,
Taco



___
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] METAPOST vardef returning multiple and non-numeric types as a single answer?

2020-03-15 Thread Gerben Wierda
I would like a vardef macro to return the pair of a picture and a bounding box. 
I don't want to use the setbound operator, because as soon as I do that, I 
cannot access the components of the picture anymore with pathpart.

I found metapost vardef returning multiple values 

 on StackExchange but that is about returning multiple values of the same 
numeric type. Is it possible to have vardef return a set of (picture, path) or 
(picture, picture) in some way? If not, I need to make two vardef macros for 
each result type.

I tried many things, amongst which:

vardef Foo( expr w, h)
% define pic
pic
end group,begingroup
% define pic
pic
endif

picture foo[]; foo = Foo( 2, 4);

___
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] metapost: remapping colors of an SVG picture

2020-02-20 Thread Hans Hagen

On 2/20/2020 10:29 AM, Jan U. Hasecke wrote:

Am 18.02.20 um 19:24 schrieb Jan U. Hasecke:

Am 18.02.20 um 19:17 schrieb mf:

Il 18/02/20 19:07, Jan U. Hasecke ha scritto:

Am 18.02.20 um 14:53 schrieb Hans Hagen:


\setupcolors[rgb=no]
\startMPcode
  draw lmt_svg [ filename = "sample.svg" ] ;
\stopMPcode

I get this error.

! Not implemented: (unknown numeric)=(string).

]
<*> ... ; p := lmt_svg [ filename = "sample.svg" ]


That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should
stand for "luametatex").


Yes, with lmtx it works but there is no image in the resulting file.


Sorry for digging deeper.

I am very thrilled by the idea that I could simply adjust a RGB SVG to
well defined CMYK colors with this trick.

Can anybody confirm if this works?
mf and i are playing with an overload mechanism (actually pretty 
trivial) ... more later but in principle the answer is yes, but


- first we have to play around a bit
- then it needs to end up in the core
- then there need to be a new context upload
- and mf has to wikify it

so, some patience is needed

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] metapost: remapping colors of an SVG picture

2020-02-20 Thread Jan U. Hasecke
Am 18.02.20 um 19:24 schrieb Jan U. Hasecke:
> Am 18.02.20 um 19:17 schrieb mf:
>> Il 18/02/20 19:07, Jan U. Hasecke ha scritto:
>>> Am 18.02.20 um 14:53 schrieb Hans Hagen:
>>>
 \setupcolors[rgb=no]
 \startMPcode
  draw lmt_svg [ filename = "sample.svg" ] ;
 \stopMPcode
>>> I get this error.
>>>
>>> ! Not implemented: (unknown numeric)=(string).
>>> 
>>> ]
>>> <*> ... ; p := lmt_svg [ filename = "sample.svg" ]
>>>
>> That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should
>> stand for "luametatex").
> 
> Yes, with lmtx it works but there is no image in the resulting file.

Sorry for digging deeper.

I am very thrilled by the idea that I could simply adjust a RGB SVG to
well defined CMYK colors with this trick.

Can anybody confirm if this works?

juh
___
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] metapost: remapping colors of an SVG picture

2020-02-18 Thread Jan U. Hasecke
Am 18.02.20 um 19:17 schrieb mf:
> Il 18/02/20 19:07, Jan U. Hasecke ha scritto:
>> Am 18.02.20 um 14:53 schrieb Hans Hagen:
>>
>>> \setupcolors[rgb=no]
>>> \startMPcode
>>>  draw lmt_svg [ filename = "sample.svg" ] ;
>>> \stopMPcode
>> I get this error.
>>
>> ! Not implemented: (unknown numeric)=(string).
>> 
>> ]
>> <*> ... ; p := lmt_svg [ filename = "sample.svg" ]
>>
> That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should
> stand for "luametatex").

Yes, with lmtx it works but there is no image in the resulting file.

juh
___
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] metapost: remapping colors of an SVG picture

2020-02-18 Thread mf

Il 18/02/20 19:07, Jan U. Hasecke ha scritto:

Am 18.02.20 um 14:53 schrieb Hans Hagen:


\setupcolors[rgb=no]
\startMPcode
     draw lmt_svg [ filename = "sample.svg" ] ;
\stopMPcode

I get this error.

! Not implemented: (unknown numeric)=(string).

]
<*> ... ; p := lmt_svg [ filename = "sample.svg" ]

That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should 
stand for "luametatex").


You find documentation about that in LMTX docs, luametafun.pdf, chapter 
"SVG".


Best wishes,

Massi

___
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] metapost: remapping colors of an SVG picture

2020-02-18 Thread Jan U. Hasecke
Am 18.02.20 um 14:53 schrieb Hans Hagen:

> 
> \setupcolors[rgb=no]
> \startMPcode
>     draw lmt_svg [ filename = "sample.svg" ] ;
> \stopMPcode

I get this error.

! Not implemented: (unknown numeric)=(string).

]
<*> ... ; p := lmt_svg [ filename = "sample.svg" ]


juh
___
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] metapost: remapping colors of an SVG picture

2020-02-18 Thread Hans Hagen

On 2/18/2020 12:18 PM, mf wrote:

Hello list,
I tried this:

\starttext
\startMPcode
picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
draw p ;
color black_rgb ; black_rgb := ( 0, 0, 0 ) ;
color red_rgb   ; red_rgb   := ( 1, 0, 0 ) ;
remapcolor( black_rgb, red_rgb ) ;
recolor p ;
draw p shifted ( bbwidth(p) + 5mm, 0) ;
\stopMPcode
\stoptext


\setupcolors[rgb=no]
\startMPcode
draw lmt_svg [ filename = "sample.svg" ] ;
\stopMPcode



but recolor gives an error:
metapost log    > >> picture
metapost log    > ! Wrong picture color model: redpart of grey object.
metapost log    >  _f_:=(redpart(EXPR0),
metapost log    > greenpart(EXPR0),bluepart(EXPR0));if.bou...
metapost log    >
metapost log    > repathed->...fi;fi;else:addto._p_.also.i;fi;endfor
metapost log    > ;setbounds._p_.to._b_;_p_
metapost log    > 
metapost log    >    ;
metapost log    > <*> ...apcolor( black_rgb, red_rgb ) ; recolor p ;
metapost log    > draw grayed p shifted ( b...
metapost log    >

My goal is to remap colors of an SVG image, like this:

\starttext
\startMPcode
picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
draw p ;
color black_rgb  ; black_rgb  := ( 0, 0, 0 ) ;
cmykcolor black_cmyk ; black_cmyk := ( 0, 0, 0, 1 ) ;
remapcolor( black_rgb, black_cmyk ) ;
recolor p ;
draw p shifted ( bbwidth(p) + 5mm, 0) ;
\stopMPcode
\stoptext

It relates to a recent thread in the mailing list about color management.
It's an attempt to use inkscape-made SVG graphics inside a CMYK 
workflow, without using color management.


Naturally it would work under some constraints, but there's a lot of 
graphics you can do with Inkscape that falls inside these:
- the number of colors in the input SVG should be limited, so that every 
color gets converted

- no embedded bitmaps, only vector graphics
- perhaps some other constraints on gradients, transparency, etc.

A good alternative would be a remapper based on a custom lua function 
like this:


function rgb2cmyk( r, g, b )
   ...
   return c, m, y, k
end

Massi

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




--

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


[NTG-context] metapost: remapping colors of an SVG picture

2020-02-18 Thread mf

Hello list,
I tried this:

\starttext
\startMPcode
picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
draw p ;
color black_rgb ; black_rgb := ( 0, 0, 0 ) ;
color red_rgb   ; red_rgb   := ( 1, 0, 0 ) ;
remapcolor( black_rgb, red_rgb ) ;
recolor p ;
draw p shifted ( bbwidth(p) + 5mm, 0) ;
\stopMPcode
\stoptext

but recolor gives an error:
metapost log> >> picture
metapost log> ! Wrong picture color model: redpart of grey object.
metapost log>  _f_:=(redpart(EXPR0),
metapost log> 
greenpart(EXPR0),bluepart(EXPR0));if.bou...

metapost log>
metapost log> repathed->...fi;fi;else:addto._p_.also.i;fi;endfor
metapost log> 
;setbounds._p_.to._b_;_p_

metapost log> 
metapost log>;
metapost log> <*> ...apcolor( black_rgb, red_rgb ) ; recolor p ;
metapost log> 
draw grayed p shifted ( b...

metapost log>

My goal is to remap colors of an SVG image, like this:

\starttext
\startMPcode
picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
draw p ;
color black_rgb  ; black_rgb  := ( 0, 0, 0 ) ;
cmykcolor black_cmyk ; black_cmyk := ( 0, 0, 0, 1 ) ;
remapcolor( black_rgb, black_cmyk ) ;
recolor p ;
draw p shifted ( bbwidth(p) + 5mm, 0) ;
\stopMPcode
\stoptext

It relates to a recent thread in the mailing list about color management.
It's an attempt to use inkscape-made SVG graphics inside a CMYK 
workflow, without using color management.


Naturally it would work under some constraints, but there's a lot of 
graphics you can do with Inkscape that falls inside these:
- the number of colors in the input SVG should be limited, so that every 
color gets converted

- no embedded bitmaps, only vector graphics
- perhaps some other constraints on gradients, transparency, etc.

A good alternative would be a remapper based on a custom lua function 
like this:


function rgb2cmyk( r, g, b )
  ...
  return c, m, y, k
end

Massi
___
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] Metapost and TikZ color code equivalent

2020-02-15 Thread Hans Hagen

On 2/15/2020 12:25 PM, Fabrice Couvreur wrote:

Hi Henri,
Why does the blue path not rotate 90 with the draw command but rotate 
with the fill command?


compare

draw  origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- 
(4.1cm,-0.05cm) -- (0.1cm,-0.05cm) -- cycle  rotated alpha withcolor red;
draw (origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- 
(4.1cm,-0.05cm) -- (0.1cm,-0.05cm) -- cycle) rotated alpha withcolor blue;





\startMPcode

   def match (expr alpha, pos) =
     fill unitsquare xscaled 4cm  yscaled 0.2cm rotated alpha shifted pos
     withcolor yellow ;
     fill origin -- (4cm,0) -- (4.1cm,-0.05cm) --  (0.1cm,-0.05cm) --
     cycle rotated alpha withcolor(.6yellow + black);
     draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
     -- (0.1cm,-0.05cm) -- cycle rotated alpha withcolor blue;
      draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
     -- (0.1cm,-0.05cm) -- cycle rotated alpha withcolor blue;
     draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
     rotated alpha;
     draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
     rotated alpha
     withshademethod "circular 1"
     withshadevector (0,1)
     withshadecolors (red,white);
     enddef;
   match(0,(0,0));
   match(90,(4.2cm,0));
   match(90,(0,0));
   match(0,(0,4.2cm));

\stopMPcode-

  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] Metapost and TikZ color code equivalent

2020-02-15 Thread Floris van Manen


On 15-02-2020 12:25, Fabrice Couvreur wrote:
> Hi Henri,
> Why does the blue path not rotate 90 with the draw command but rotate
> with the fill command?
> 

Why not draw the match as a picture first, then rotate and shift that
picture?
Also, if you use a local scale unit, it will be easier to stach the
matches together by merely applying a factor in match units.

.F


pEpkey.asc
Description: application/pgp-keys
___
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] Metapost and TikZ color code equivalent

2020-02-15 Thread Fabrice Couvreur
Hi Henri,
Why does the blue path not rotate 90 with the draw command but rotate with
the fill command ?

\startMPcode

  def match (expr alpha, pos) =
fill unitsquare xscaled 4cm  yscaled 0.2cm rotated alpha shifted pos
withcolor yellow ;
fill origin -- (4cm,0) -- (4.1cm,-0.05cm) --  (0.1cm,-0.05cm) --
cycle rotated alpha withcolor(.6yellow + black);
draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
-- (0.1cm,-0.05cm) -- cycle rotated alpha withcolor blue;
 draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
-- (0.1cm,-0.05cm) -- cycle rotated alpha withcolor blue;
draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
rotated alpha;
draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
rotated alpha
withshademethod "circular 1"
withshadevector (0,1)
withshadecolors (red,white);
enddef;
  match(0,(0,0));
  match(90,(4.2cm,0));
  match(90,(0,0));
  match(0,(0,4.2cm));

\stopMPcode


Le sam. 15 févr. 2020 à 00:01, Fabrice Couvreur 
a écrit :

> Hi,
> Hi,
> I have corrected for the dimensions of the ellipse but I cannot achieve
> the same effect for the red color.
> Thank you.
> Fabrice
> \startMPcode
>   def match (expr pos) =
> fill unitsquare xscaled 4cm  yscaled 0.2cm shifted pos withcolor
> yellow;
> fill origin -- (4cm,0) -- (4.1cm,-0.05cm) --  (0.1cm,-0.05cm) -- cycle
>  withcolor(.6yellow + black);
> draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
> -- (0.1cm,-0.05cm) -- cycle;
> fill fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
> withcolor red;
> draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm);
> draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
>  withshademethod "circular"
>  withshadevector (0,1)
>  withshadecolors (red,white)
>   enddef;
>   match((0,0));
>
> \stopMPcode
>
>
>
> Le ven. 14 févr. 2020 à 16:43, Fabrice L  a
> écrit :
>
>> Hi,
>>
>> Le 13 févr. 2020 à 16:45, Fabrice Couvreur 
>> a écrit :
>>
>>
>> How to have the color defined by {yellow!60!black} with Metapost ?
>>
>>
>> color MyColor ; MyColor := .6[yellow,black] ;
>>
>> See metafun manual, section 1.13.
>>
>> Thank you.
>> Fabrice
>>
>>
>> Fabrice (another one !).
>>
>>
>> ___
>> 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
>>
>> ___
>>
>
___
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] Metapost and TikZ color code equivalent

2020-02-14 Thread Fabrice Couvreur
Hi,
Hi,
I have corrected for the dimensions of the ellipse but I cannot achieve the
same effect for the red color.
Thank you.
Fabrice
\startMPcode
  def match (expr pos) =
fill unitsquare xscaled 4cm  yscaled 0.2cm shifted pos withcolor yellow;
fill origin -- (4cm,0) -- (4.1cm,-0.05cm) --  (0.1cm,-0.05cm) -- cycle
 withcolor(.6yellow + black);
draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
-- (0.1cm,-0.05cm) -- cycle;
fill fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
withcolor red;
draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm);
draw fullcircle xscaled 0.50cm yscaled 0.44cm shifted (4.125cm,0.1cm)
 withshademethod "circular"
 withshadevector (0,1)
 withshadecolors (red,white)
  enddef;
  match((0,0));

\stopMPcode



Le ven. 14 févr. 2020 à 16:43, Fabrice L  a écrit :

> Hi,
>
> Le 13 févr. 2020 à 16:45, Fabrice Couvreur 
> a écrit :
>
>
> How to have the color defined by {yellow!60!black} with Metapost ?
>
>
> color MyColor ; MyColor := .6[yellow,black] ;
>
> See metafun manual, section 1.13.
>
> Thank you.
> Fabrice
>
>
> Fabrice (another one !).
>
>
> ___
> 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
>
> ___
>
___
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] Metapost and TikZ color code equivalent

2020-02-14 Thread Fabrice L
Hi,

> Le 13 févr. 2020 à 16:45, Fabrice Couvreur  a 
> écrit :

> How to have the color defined by {yellow!60!black} with Metapost ?

color MyColor ; MyColor := .6[yellow,black] ;

See metafun manual, section 1.13.

> Thank you.
> Fabrice

Fabrice (another one !).
> ___
> 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
___


Re: [NTG-context] Metapost and TikZ color code equivalent

2020-02-14 Thread Fabrice Couvreur
i Henri,
Thank you for your answer. The idea is to make the graph as an attachment. I
converted to Metapost but the road is still long!
The code is from percusse on StackExchange. As you can see, there is a
problem with the ellipse. How do I fix this ?
Thank you
Fabrice

\usemodule[tikz]
\starttext
\startMPcode
  def match (expr pos) =
fill unitsquare xscaled 4cm  yscaled 0.2cm shifted pos withcolor yellow;
fill origin -- (4cm,0) -- (4.1cm,-0.05cm) --  (0.1cm,-0.05cm) -- cycle
 withcolor(.6yellow + black);
draw origin -- (0,0.2cm) -- (4cm,0.2cm) -- (4cm,0) -- (4.1cm,-0.05cm)
-- (0.1cm,-0.05cm) -- cycle;
fill fullcircle xscaled 0.25cm yscaled 0.22cm shifted (4.125cm,0.1cm)
withcolor red;
draw fullcircle xscaled 0.25cm yscaled 0.22cm shifted (4.125cm,0.1cm)
 withshademethod "circular"
 withshadevector (0,1)
 withshadecolors (red,white)
  enddef;
  match((0,0));

\stopMPcode

\starttikzpicture
\define[2]\allumette{
\fill [yellow] (#1,#2) rectangle (#1+4,#2+0.2);
\fill [yellow!60!black] (#1,#2) -- ++(4,0)-- ++(0.1,-0.05) -- ++(-4,0)
-- ++(-0.1,0.05);
\draw (#1,#2) -- ++(0,0.2) -- ++(4,0) -- ++(0,-0.2) -- ++(0.1,-0.05) --
++(-4,0) -- ++(-0.1,0.05);
\shade[ball color=red] (#1+4,#2+0.1) ellipse (0.25cm and 0.22cm);
\draw (#1+4,#2+0.1) ellipse (0.25cm and 0.22cm);
}
\allumette{0.1}{0.2}
\filldraw[orange,scale=0.5,shift={(8.2,1.2)}]  (0,0) .. controls
(-1.5,1.25) and (.5,2) .. (-.2,4) .. controls (1,2.5) and (1,.5) .. (0,0);
\stoptikzpicture
\stoptext

Le ven. 14 févr. 2020 à 02:49, Henri Menke  a écrit :

> On 2/14/20 10:45 AM, Fabrice Couvreur wrote:
> > Hi,
> > How to have the color defined by {yellow!60!black} with Metapost ?
>
> \usemodule[tikz]
> \starttext
> \startMPcode
> fill fullsquare scaled 1cm withcolor (.6yellow + black) ;
> \stopMPcode
>
> \starttikzpicture
> \fill[yellow!60!black] (0,0) rectangle (1,1);
> \stoptikzpicture
> \stoptext
>
>
> > Thank you.
> > Fabrice
> >
> >
> >
> ___
> > 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
>
> ___
>
___
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] Metapost and TikZ color code equivalent

2020-02-13 Thread Henri Menke
On 2/14/20 10:45 AM, Fabrice Couvreur wrote:
> Hi,
> How to have the color defined by {yellow!60!black} with Metapost ?

\usemodule[tikz]
\starttext
\startMPcode
fill fullsquare scaled 1cm withcolor (.6yellow + black) ;
\stopMPcode

\starttikzpicture
\fill[yellow!60!black] (0,0) rectangle (1,1);
\stoptikzpicture
\stoptext


> Thank you.
> Fabrice
> 
> 
> ___
> 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] Metapost and TikZ color code equivalent

2020-02-13 Thread Fabrice Couvreur
Hi,
How to have the color defined by {yellow!60!black} with Metapost ?
Thank you.
Fabrice
___
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] MetaPost with Multiple Variable Sections

2019-09-18 Thread Jeong Dal
Dear Jeroen,

If you change “pair a;” to “numeric a;” in the second MPcode, it draws a circle 
without error.

Best regards,

Dalyoung

> 
> \placefloatright{}{
> \startMPcode
> pair a;

numeric a;

> a := 2cm;
> draw fullcircle scaled (2*a);
> \stopMPcode}
> 
> \stoptext
> 

___
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] MetaPost with Multiple Variable Sections

2019-09-18 Thread Aditya Mahajan

On Wed, 18 Sep 2019, Jeroen wrote:


\startMPcode
pair a;
a := 2cm;


You define a to be a pair and then assign it to a number. Metapost is 
telling you that you cannot do that:



(xpart a,ypart a)
56.6929

! Equation cannot be performed (pair=numeric).

;
<*> pair a; a := 2cm;
draw fullcircle scaled (2*a); ;
I'm sorry, but I don't know how to make such things equal.
(See the two expressions just above the error message.)

You can fix that by saying

numeric a;
a := 2cm;

One needs to keep in mind that all the code in multiple MPcode 
environments are run in the same scope. I occasonally use


\startMPcode
begingroup;
...
endgroup;
\stopMPcode

to avoid interference.

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
___


[NTG-context] MetaPost with Multiple Variable Sections

2019-09-18 Thread Jeroen
I have been working with MetaPost as following, which worked fine with one
startMPcode section with variables, but with 2 startMPcode Metapost
sections, it keeps telling me the numbers dont add up:


\definefloat  [floatright][figure]
\setupfloat   [floatright][default={right,none}]
\setuplayout  [backspace=20mm,width=170mm,topspace=20mm,height=250mm]

\starttext

\placefloatright{}{
\startMPcode
pair a, b;
a := (0,0);
b := (50,50);
draw a -- b;
\stopMPcode}

\placefloatright{}{
\startMPcode
pair a;
a := 2cm;
draw fullcircle scaled (2*a);
\stopMPcode}

\stoptext


I also have tried with the startbuffer combination as below, but this gave
the same error codes. Is there any other way of working with multiple
MetaPost sections with variables in a single document?


\definefloat  [floatright][figure]
\setupfloat   [floatright][default={right,none}]
\setuplayout  [backspace=20mm,width=170mm,topspace=20mm,height=250mm]

\starttext

\startbuffer
\startMPcode
pair a, b;
a := (0,0);
b := (50,50);
draw a -- b;
\stopMPcode
\stopbuffer

\floatright{}{\getbuffer}

\startbuffer
\startMPcode
pair a;
a := 2cm;
draw fullcircle scaled (2*a);
\stopMPcode
\stopbuffer

\floatright{}{\getbuffer}

\stoptext
___
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] Metapost graphic in setupbackground

2019-02-08 Thread Jan U. Hasecke
Thanks a lot Wolfgang and Marco. :-)

juh

Am 08.02.19 um 12:57 schrieb Wolfgang Schuster:
> 
> 
> Jan U. Hasecke schrieb am 08.02.19 um 12:36:
>> Hi all,
>>
>> I make my first steps with Metapost.
>>
>> I would like to set the background of all pages to a Metapost graphic.
>>
>> But only the first page has the defined background.
>>
>> I also tried with
>>
>> \startuseMPgraphic
>>
>> with no success
>>
>> --- mwe ---
>>
>> \startreusableMPgraphic{kreis}
>> draw fullcircle scaled 70mm withcolor red withpen pencircle scaled 6mm;
>> \stopreusableMPgraphic
>>
>> \definelayer[kreisbackground][width=70mm,height=70mm]
> 
> \definelayer[kreisbackground][state=repeat]
> 
> Wolfgang
> 

___
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] Metapost graphic in setupbackground

2019-02-08 Thread Wolfgang Schuster



Jan U. Hasecke schrieb am 08.02.19 um 12:36:

Hi all,

I make my first steps with Metapost.

I would like to set the background of all pages to a Metapost graphic.

But only the first page has the defined background.

I also tried with

\startuseMPgraphic

with no success

--- mwe ---

\startreusableMPgraphic{kreis}
draw fullcircle scaled 70mm withcolor red withpen pencircle scaled 6mm;
\stopreusableMPgraphic

\definelayer[kreisbackground][width=70mm,height=70mm]


\definelayer[kreisbackground][state=repeat]

Wolfgang

___
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] Metapost graphic in setupbackground

2019-02-08 Thread Marco Patzer
On Fri, 8 Feb 2019 12:36:16 +0100
"Jan U. Hasecke"  wrote:

> \definelayer[kreisbackground][width=70mm,height=70mm]

\definelayer[kreisbackground][width=70mm,height=70mm, state=repeat]

start: layer appears only on the current page
stop : layer doesn't show up
repeat   : layer prints on all pages
next : layer appears on the following page
continue : layer appears on all pages except the first

> \setupbackgrounds[paper][background=kreisbackground, state=start]

\setupbackgrounds[paper][background=kreisbackground]

Marco
___
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] Metapost graphic in setupbackground

2019-02-08 Thread Jan U. Hasecke
Hi all,

I make my first steps with Metapost.

I would like to set the background of all pages to a Metapost graphic.

But only the first page has the defined background.

I also tried with

\startuseMPgraphic

with no success

--- mwe ---

\startreusableMPgraphic{kreis}
draw fullcircle scaled 70mm withcolor red withpen pencircle scaled 6mm;
\stopreusableMPgraphic

\definelayer[kreisbackground][width=70mm,height=70mm]

\setlayer[kreisbackground]
  [x=-3mm,y=-3mm]
  {\reuseMPgraphic{kreis}}

\setupbackgrounds[paper][background=kreisbackground, state=start]

\starttext

\input lorem

\page

\input lorem

\stoptext


TIA
juh
___
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] MetaPost shading broken with latest beta

2018-06-24 Thread Hans Hagen

On 6/24/2018 12:17 AM, Adam Reviczky wrote:

Hi,

Using the shading function in a metapost image the whole page is
filled in instead of the figure that defines it.

Minimal example as from the metafun manual 8.3.3
(http://www.pragma-ade.nl/general/manuals/metafun-p.pdf):
\starttext
\startMPcode
fill fullsquare xyscaled (1cm,1cm)
withshademethod "linear"
withshadevector (1,0)
withshadecolors (darkred,darkgreen)
;
\stopMPcode
\stoptext

ConTeXt  ver: 2018.06.23 12:12 MKIV beta  fmt: 2018.6.23  int: english/english
luatex version 1.09 with functionality level 6823,
MetaPost 2.00

With this, I get a full A4 page with the shading colors.
This worked until the beta 2018-06-22 16:02 and the desired output is
shown when using live.contextgarden.net.
fixed a next beta ... this relates to the context mp inclusion handler 
now following a one-pass approach (again experimental and only > 1.08)


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
___

[NTG-context] MetaPost shading broken with latest beta

2018-06-23 Thread Akira Kakuto

With this, I get a full A4 page with the shading colors.
This worked until the beta 2018-06-22 16:02 and the desired output is
shown when using live.contextgarden.net.


Even in the previous
mtx-context | current version: 2018.06.22 15:55
I get a full A4 page with the shading colors if I use
Luatex 1.09.0
Development id: 6823

The desired output is obtained if I use
Luatex 1.08.0
Development id: 6731

So I think the latest experimental binary is problematic
in this example.

Best,
Akira

___
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] MetaPost shading broken with latest beta

2018-06-23 Thread Adam Reviczky
Hi,

Using the shading function in a metapost image the whole page is
filled in instead of the figure that defines it.

Minimal example as from the metafun manual 8.3.3
(http://www.pragma-ade.nl/general/manuals/metafun-p.pdf):
\starttext
\startMPcode
fill fullsquare xyscaled (1cm,1cm)
withshademethod "linear"
withshadevector (1,0)
withshadecolors (darkred,darkgreen)
;
\stopMPcode
\stoptext

ConTeXt  ver: 2018.06.23 12:12 MKIV beta  fmt: 2018.6.23  int: english/english
luatex version 1.09 with functionality level 6823,
MetaPost 2.00

With this, I get a full A4 page with the shading colors.
This worked until the beta 2018-06-22 16:02 and the desired output is
shown when using live.contextgarden.net.

Thanks,
Adam
___
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] Metapost: How to get total number of pages?

2017-11-17 Thread Procházka Lukáš Ing .

Hello Thomas,

thank you, I'll keep it in mind!

Best regards,

Lukas


On Fri, 17 Nov 2017 14:42:58 +0100, Thomas A. Schmitz 
 wrote:


On 17.11.2017 14:02, Procházka Lukáš Ing. wrote:

it seems that there is 'PageNumber' variable (macro) available within MP
code, maybe introduced by 'StartPage', within MP.

How do I get total number of pages or last page number within MP (in
Ctx: \totalnumberofpages, \lastpage)?


NOfPages

If you had grepped the source for PageNumber, you would have discovered
that all of this is defined in meta-pag.mkiv.

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
___



--
Ing. Lukáš Procházka | mailto:l...@pontex.cz
Pontex s. r. o.  | mailto:pon...@pontex.cz | http://www.pontex.cz | 
IDDS:nrpt3sn
Bezová 1658
147 14 Praha 4

Mob.: +420 702 033 396

___
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] Metapost: How to get total number of pages?

2017-11-17 Thread Thomas A. Schmitz

On 17.11.2017 14:02, Procházka Lukáš Ing. wrote:
it seems that there is 'PageNumber' variable (macro) available within MP 
code, maybe introduced by 'StartPage', within MP.


How do I get total number of pages or last page number within MP (in 
Ctx: \totalnumberofpages, \lastpage)?


NOfPages

If you had grepped the source for PageNumber, you would have discovered 
that all of this is defined in meta-pag.mkiv.


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
___

  1   2   3   4   5   6   7   >