From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/111875 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeong Dal Newsgroups: gmane.comp.tex.context Subject: Re: simplifying repeated macro calls in metafun Date: Thu, 24 Jun 2021 05:26:25 +0900 Message-ID: <804761E2-A68A-463F-9182-EE11D13D8850@me.com> References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Content-Type: multipart/mixed; boundary="===============4237967436348832604==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33635"; mail-complaints-to="usenet@ciao.gmane.io" To: "list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl" Original-X-From: ntg-context-bounces@ntg.nl Wed Jun 23 22:27:23 2021 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lw9T0-0008X0-U4 for gctc-ntg-context-518@m.gmane-mx.org; Wed, 23 Jun 2021 22:27:22 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 7D1E0284B7A; Wed, 23 Jun 2021 22:26:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7hC6BlI3S_nm; Wed, 23 Jun 2021 22:26:35 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D2C25284B90; Wed, 23 Jun 2021 22:26:35 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B7D0B284B88 for ; Wed, 23 Jun 2021 22:26:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yRlqEbHNbTWn for ; Wed, 23 Jun 2021 22:26:33 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=17.58.6.54; helo=pv50p00im-tydg10021701.me.com; envelope-from=haksan@me.com; receiver= Original-Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id C589B284B7A for ; Wed, 23 Jun 2021 22:26:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1624479991; bh=Jhu5JjeFakPdM9aowHn6NxcG9Rhxrg/43W8gKGQRfo0=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=DjPJNJ+FXwJHkz3p5LS2J7NB3Qh7+yyE5S/+zBw/uXfeDqmSPHS5bD/yXph+SQSh9 Kvhi5ygBUjhy0XfQCJwMVri5ggU5Yz/PsRTpxVyO6ljkdiPjWU/jS57Gl9ewS9Yq4P O/3bOraJoM9lihb4W/h3ShSTIZsEssIke3VdOjYaD7bGy4rfeoYn2MgyjFPRIWeXfi 30Uc0ycYDvQIoIBZ0a9Alokj7svdqIyL5wiKOcInQXL99TbMKoDy16jsgqh0qjcmx5 bICa/nHIJ6oZXA8omy6U3nHm8P7FtE9HbAch36qIsSdONWqpIaLDjfNTTfx7b84M1N 7x2eaCtOOuSww== Original-Received: from smtpclient.apple (unknown [222.232.154.22]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 6C657840282 for ; Wed, 23 Jun 2021 20:26:29 +0000 (UTC) In-Reply-To: X-Mailer: Apple Mail (2.3654.100.0.2.22) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-23_12:2021-06-23, 2021-06-23 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=811 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2106230118 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:111875 Archived-At: --===============4237967436348832604== Content-Type: multipart/alternative; boundary="Apple-Mail=_D899EEF5-85EC-4CDD-A2CB-DEDADA07D73C" --Apple-Mail=_D899EEF5-85EC-4CDD-A2CB-DEDADA07D73C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Dear Otared, >=20 > Regarding the way Aditya uses \startuseMPgraphic, it is also very = instructive.=20 > Dalyoung, can you also share the animation example for the foldings ? = I am sure we are a few on the list to learn something=E2=80=A6 >=20 1. Here is the working sample of animation using \processMPbuffer which = I did before. You can see it using adobe reader. \startbuffer[UDBasic] pair A,B,C,D; pair E, F, G, H; path p,q; numeric ang,maxNum; u:=3D1in; A=3D(.95*TextWidth,u); B=3D(0,u); C=3D(0,0); D=3D(.95*TextWidth,0); p :=3D A--B--C--D; q :=3D (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle; z0=3D(.1u,0); =20 vardef nextPt (expr M,N) =3D=20 if ypart(N) =3D 0:=20 H :=3D whatever[N, N + dir(.5*angle(M-N))*u] =3D whatever[A,B]; else: H :=3D whatever[N, N + dir(.5*angle(M-N))*u] =3D whatever[C,D]; fi; H enddef; def grayUD(expr i) =3D draw G -- if ypart(B)=3Dypart(G): B -- C else: C -- B fi --z[i]; filldraw z[i]+2*(G-z[i])*u -- z[i] -- z[i+1] -- z[i+1]+(G-z[i])*u = -- cycle withcolor .75white;=20 draw G -- z[i+1] dashed evenly; draw z[0] for k=3D0 upto i: --z[k] endfor dashed evenly; clip currentpicture to q; setbounds currentpicture to boundingbox q; enddef; def linesUD(expr i) =3D draw p; draw z0 for k=3D0 upto i+1: --z[k] endfor dashed evenly; setbounds currentpicture to boundingbox q; enddef; \stopbuffer \startbuffer[UDpts] ang :=3D 40; z[1] =3D whatever[z[0], z[0]+dir(ang)*u] =3D whatever[A,B]; G :=3D whatever[z[0], z[0]+dir(2*ang)*u] =3D whatever[A,B]; for k =3D 2 upto 20: z[k] =3D nextPt(z[k-2],z[k-1]); maxNum :=3D k; exitif xpart(z[k]) > TextWidth; endfor; \stopbuffer \startbuffer[UD0] draw p; setbounds currentpicture to boundingbox q; \stopbuffer \startbuffer[UD1] grayUD(0); \stopbuffer \startbuffer[UD11] linesUD(0); \stopbuffer \startbuffer[UD2] G :=3D z0; grayUD(1) \stopbuffer \startbuffer[UD21] linesUD(1); \stopbuffer \startbuffer[UD3] G :=3D z1; grayUD(2); \stopbuffer \startbuffer[UD31] linesUD(2); \stopbuffer \startbuffer[UD4] G :=3D z2; grayUD(3); \stopbuffer \startbuffer[UD41] linesUD(3); \stopbuffer \startbuffer[UD5] G :=3D z3; grayUD(4); \stopbuffer \startbuffer[UD51] linesUD(4); \stopbuffer \startbuffer[UDFinal] draw p; draw z0--z1--z2--z3--z4--z5--z6--z7--z8 dashed evenly; setbounds currentpicture to boundingbox q; \stopbuffer \setupinteraction[state=3Dstart] \usemodule[animation] \starttext \startanimation[menu=3Dyes] {\processMPbuffer[UDBasic,UDpts,UD0]} {\processMPbuffer[UDBasic,UDpts,UD1]} {\processMPbuffer[UDBasic,UDpts,UD11]} {\processMPbuffer[UDBasic,UDpts,UD2]} {\processMPbuffer[UDBasic,UDpts,UD21]} {\processMPbuffer[UDBasic,UDpts,UD3]} {\processMPbuffer[UDBasic,UDpts,UD31]} {\processMPbuffer[UDBasic,UDpts,UD4]} {\processMPbuffer[UDBasic,UDpts,UD41]} {\processMPbuffer[UDBasic,UDpts,UD5]} {\processMPbuffer[UDBasic,UDpts,UD51]} {\processMPbuffer[UDBasic,UDpts,UDFinal]} \stopanimation \stoptext Now, I am trying to do the same thing using \startuseMPgraphic, but I = don=E2=80=99t the correct result yet. Using \startuseMPgraphic, and \dorecurse, the code is simpler. But, it = seems to me that \startanimation =E2=80=A6 \stopanimation is not working = with \dorecurse{}{} =E2=80=A6 It just list all the graphics. Any hint is welcome. \startMPinitializations%{UDBasic} pair A,B,C,D; pair E, F, G, H; path p,q; numeric ang,maxNum; numeric n; %AM Added u:=3D1in; A=3D(.95*TextWidth,u); B=3D(0,u); C=3D(0,0); D=3D(.95*TextWidth,0); p :=3D A--B--C--D; q :=3D (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle; z0=3D(.1u,0); =20 vardef nextPt (expr M,N) =3D=20 if ypart(N) =3D 0:=20 H :=3D whatever[N, N + dir(.5*angle(M-N))*u] =3D whatever[A,B]; else: H :=3D whatever[N, N + dir(.5*angle(M-N))*u] =3D whatever[C,D]; fi; H enddef; def grayUD(expr i) =3D draw G -- if ypart(B)=3Dypart(G): B -- C else: C -- B fi --z[i]; filldraw z[i]+2*(G-z[i])*u -- z[i] -- z[i+1] -- z[i+1]+(G-z[i])*u = -- cycle withcolor .75white;=20 draw G -- z[i+1] dashed evenly; draw z[0] for k=3D0 upto i: --z[k] endfor dashed evenly; clip currentpicture to q; enddef; def linesUD(expr i) =3D draw p; draw z0 for k=3D0 upto i+1: --z[k] endfor dashed evenly; % AM: removed. Set in in the main code % setbounds currentpicture to boundingbox q; enddef; ang :=3D 40; z[1] =3D whatever[z[0], z[0]+dir(ang)*u] =3D whatever[A,B]; % AM: Changed next line from G to z[-1] z[-1] =3D whatever[z[0], z[0]+dir(2*ang)*u] =3D whatever[A,B]; for k =3D 2 upto 20: z[k] =3D nextPt(z[k-2],z[k-1]); maxNum :=3D k; exitif xpart(z[k]) > TextWidth; endfor; \stopMPinitializations \startuseMPgraphic{foldUD}{num} numeric n; n :=3D \MPvar{num}-1; G :=3D z[n-1]; grayUD(n); \stopuseMPgraphic \startuseMPgraphic{dotLines}{num} numeric n; n :=3D \MPvar{num}-1; linesUD(n); \stopuseMPgraphic \setupinteraction[state=3Dstart] \usemodule[animation] \starttext \startanimation[menu=3Dyes] \dorecurse{7} { {\useMPgraphic{foldUD}{num=3D\recurselevel}} {\useMPgraphic{dotLines}{num=3D\recurselevel}} } \stopanimation \stoptext Best regards, Dalyoung --Apple-Mail=_D899EEF5-85EC-4CDD-A2CB-DEDADA07D73C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Dear Otared,


Regarding the way Aditya uses \startuseMPgraphic, it is also = very instructive.
Dalyoung, can you also share the = animation example for the foldings ? I am sure we are a few on the list = to learn something=E2=80=A6


1. = Here is the working sample of animation using \processMPbuffer which I = did before. You can see it using adobe reader.


\startbuffer[UDBasic]
pair A,B,C,D;
pair E, F, G, H;
path p,q;
numeric ang,maxNum;
u:=3D1in;
= A=3D(.95*TextWidth,u); B=3D(0,u); C=3D(0,0); D=3D(.95*TextWidth,0);
p :=3D A--B--C--D;
q :=3D (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle;
z0=3D(.1u,0);
= vardef nextPt (expr = M,N) =3D
= if ypart(N) =3D 0:
H :=3D whatever[N, N + dir(.5*angle(M-N))*u] = =3D whatever[A,B];
else:
H :=3D= whatever[N, N + dir(.5*angle(M-N))*u] = =3D whatever[C,D];
fi;
H
enddef;

def grayUD(expr i) =3D
draw G -- if ypart(B)=3Dypart(G): = B -- C else: C -- B fi --z[i];
filldraw z[i]+2*(G-z[i])*u= -- z[i] -- z[i+1] = -- z[i+1]+(G-z[i])*u= -- cycle withcolor = .75white;
draw G -- z[i+1] = dashed evenly;
draw z[0] for k=3D0 upto i: --z[k] = endfor dashed evenly;
clip currentpicture to = q;
setbounds currentpicture to boundingbox = q;
enddef;

= def linesUD(expr = i) =3D
draw = p;
draw z0 for k=3D0 upto i+1: --z[k] = endfor dashed evenly;
setbounds = currentpicture to boundingbox q;
= enddef;
\stopbuffer

\startbuffer[UDpts]
ang :=3D 40;
z[1] =3D whatever[z[0], = z[0]+dir(ang)*u] = =3D whatever[A,B];
G :=3D whatever[z[0], z[0]+dir(2*ang)*u] = =3D whatever[A,B];
for k =3D 2 upto 20:
z[k] = =3D nextPt(z[k-2],z[k-1]);
maxNum :=3D k;
= exitif xpart(z[k]) > TextWidth;
= endfor;
\stopbuffer
\startbuffer[UD0]
draw p;
= setbounds currentpicture to boundingbox q;
\stopbuffer
\startbuffer[UD1]
grayUD(0);
\stopbuffer
\startbuffer[UD11]
linesUD(0);
\stopbuffer
\startbuffer[UD2]
G :=3D z0;
grayUD(1)
\stopbuffer
\startbuffer[UD21]
linesUD(1);
\stopbuffer
\startbuffer[UD3]
G :=3D z1;
grayUD(2);
\stopbuffer
\startbuffer[UD31]
linesUD(2);
\stopbuffer
\startbuffer[UD4]
G :=3D z2;
grayUD(3);
\stopbuffer
\startbuffer[UD41]
linesUD(3);
\stopbuffer
\startbuffer[UD5]
G :=3D z3;
grayUD(4);
\stopbuffer
\startbuffer[UD51]
linesUD(4);
\stopbuffer
\startbuffer[UDFinal]
draw p;
draw= z0--z1--z2--z3--z4--z5--z6--z7--z8 dashed evenly;
setbounds = currentpicture to boundingbox q;
\stopbuffer

\setupinteraction[state=3Dstart]
\usemodule[animation]
\starttext
\startanimation[menu=3Dyes]
{\processMPbuffer[UDBasic,UDpts,UD0]}
{\processMPbuffer[UDBasic,UDpts,UD1]}
{\processMPbuffer[UDBasic,UDpts,UD11]}
{\processMPbuffer[UDBasic,UDpts,UD2]}
{\processMPbuffer[UDBasic,UDpts,UD21]}
{\processMPbuffer[UDBasic,UDpts,UD3]}
{\processMPbuffer[UDBasic,UDpts,UD31]}
{\processMPbuffer[UDBasic,UDpts,UD4]}
{\processMPbuffer[UDBasic,UDpts,UD41]}
{\processMPbuffer[UDBasic,UDpts,UD5]}
{\processMPbuffer[UDBasic,UDpts,UD51]}
{\processMPbuffer[UDBasic,UDpts,UDFinal]}
\stopanimation
\stoptext

Now, I am trying to do = the same thing using \startuseMPgraphic, but I don=E2=80=99t the correct = result yet.
Using \startuseMPgraphic, and = \dorecurse, the code is simpler. But, it seems to me that = \startanimation =E2=80=A6 \stopanimation is not working with = \dorecurse{}{} =E2=80=A6
It just list all the = graphics.
Any hint is welcome.

\startMPinitializations%{UDBasic}
pair A,B,C,D;
pair E, F, G, H;
path = p,q;
numeric ang,maxNum;

numeric n; %AM Added

u:=3D1in;
A=3D(.95*TextWidth,u); B=3D(0,u); = C=3D(0,0); D=3D(.95*TextWidth,0);
p :=3D A--B--C--D;
= q :=3D (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle;
z0=3D(.1u,0);
= vardef= nextPt (expr = M,N) =3D
= if = ypart(N) = =3D 0:
H :=3D whatever[N, N + dir(.5*angle(M-N))*u] = =3D whatever[A,B];
else:
H :=3D whatever[N, N + dir(.5*angle(M-N))*u] = =3D whatever[C,D];
fi;
= H
enddef;

= def = grayUD(expr = i) =3D
draw G = -- = if = ypart(B)=3Dypart(G): = B -- = C else: = C -- = B fi = --z[i];
filldraw z[i]+2*(G-z[i])*u = -- = z[i] -- z[i+1] = -- = z[i+1]+(G-z[i])*u = -- = cycle = withcolor .75white;
draw G -- z[i+1] = dashed= evenly;
draw z[0] = for = k=3D0 upto i: --z[k] = endfor= dashed evenly;
clip currentpicture to q;
= enddef;

def = linesUD(expr = i) =3D
draw = p;
draw z0 for k=3D0 = upto = i+1: --z[k] = endfor= dashed evenly;

= % AM: removed. Set in in = the main code
% setbounds currentpicture to boundingbox = q;
enddef;

ang :=3D 40;
z[1] = =3D whatever[z[0], = z[0]+dir(ang)*u] = =3D whatever[A,B];

% AM: Changed next line from G to = z[-1]
z[-1] = =3D whatever[z[0], = z[0]+dir(2*ang)*u] = =3D whatever[A,B];
for k =3D 2 upto 20:
z[k] =3D = nextPt(z[k-2],z[k-1]);
maxNum :=3D k;
= exitif xpart(z[k]) = > = TextWidth;
endfor;

\stopMPinitializations

\startuseMPgraphic{foldUD}{num}
numeric n;
n :=3D = \MPvar{num}-1;
G :=3D z[n-1];
grayUD(n);
\stopuseMPgraphic
\startuseMPgraphic{dotLines}{num}
numeric n;
n :=3D = \MPvar{num}-1;
linesUD(n);
\stopuseMPgraphic

\setupinteraction[state=3Dstart]
\usemodule[animation]
\starttext
\startanimation[menu=3Dyes]
\dorecurse{7}
{
{\useMPgraphic{foldUD}{num=3D\recurselevel}}
{\useMPgraphic{dotLines}{num=3D\recurselevel}}
}
\stopanimation
\stoptext

Best regards,

Dalyoung

= --Apple-Mail=_D899EEF5-85EC-4CDD-A2CB-DEDADA07D73C-- --===============4237967436348832604== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============4237967436348832604==--