From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/111883 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: Delivering the value of a variable in MetaFun to ConTeXt Date: Wed, 23 Jun 2021 23:39:02 -0400 (EDT) Message-ID: References: <1d2d97dc-0095-6547-4625-1a264cc455b3@xs4all.nl> <586CFBE5-4AFC-48C9-A7BB-37159C1CA5A6@me.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-1559906599-1624505943=:827465" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3230"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Alpine 2.23 (LNX 453 2020-06-18) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 24 05:39:37 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 1lwGDI-0000Z8-LI for gctc-ntg-context-518@m.gmane-mx.org; Thu, 24 Jun 2021 05:39:36 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 3C59C284A8C; Thu, 24 Jun 2021 05:39:08 +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 e4BdLNT_B1YL; Thu, 24 Jun 2021 05:39:07 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 3116F284B90; Thu, 24 Jun 2021 05:39:07 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 62424284B90 for ; Thu, 24 Jun 2021 05:39:05 +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 iu6bCanfzMAp for ; Thu, 24 Jun 2021 05:39:04 +0200 (CEST) Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=132.206.73.2; helo=orford.cim.mcgill.ca; envelope-from=adityam@umich.edu; receiver= Original-Received: from orford.cim.mcgill.ca (orford.cim.mcgill.ca [132.206.73.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 88DA7284A8C for ; Thu, 24 Jun 2021 05:39:04 +0200 (CEST) Original-Received: from adi-thinkpad (198-48-192-62.cpe.teksavvy.com [198.48.192.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adityam) by orford.cim.mcgill.ca (Postfix) with ESMTPSA id 2572C114BAC for ; Wed, 23 Jun 2021 23:39:03 -0400 (EDT) In-Reply-To: <586CFBE5-4AFC-48C9-A7BB-37159C1CA5A6@me.com> 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:111883 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1559906599-1624505943=:827465 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Thu, 24 Jun 2021, Jeong Dal wrote: > Dear Hans, >=20 > Your code works fine. >=20 > > \starttext > >=20 > > \startMPcode > > numeric maxCount; > > maxCount :=3D 10; > > setglobalmacro("MyMacro",decial maxCount); > > setglobalcount("MyCount",maxCount); > > \stopMPcode > >=20 > >=20 > > \dorecurse{\MyMacro}{It is \recurselevel. }\par > > \dorecurse{\MyCount}{It is \recurselevel. }\par > >=20 > > \stoptext >=20 > I applied your method to my code as following.=20 >=20 > \newcount\udCount %%% add count > \startMPinitializations%{UDBasic} > pair A,B,C,D; > pair E, F, G, H; > path p,q; > numeric ang,maxNum; >=20 > numeric n; %AM Added >=20 > 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; >=20 > 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; >=20 > def linesUD(expr i) =3D > draw p; > draw z0 for k=3D0 upto i+1: --z[k] endfor dashed evenly; >=20 > % AM: removed. Set in in the main code > % setbounds currentpicture to boundingbox q; > enddef; >=20 > ang :=3D 40; > z[1] =3D whatever[z[0], z[0]+dir(ang)*u] =3D whatever[A,B]; >=20 > % 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; > maxNum :=3D maxNum-1; > setglobalmacro("udMacro",decimal maxNum); %%% define udMacro and udCo= unt > setglobalcount("udCount",maxNum); >=20 > \stopMPinitializations >=20 > \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 >=20 > \setupinteraction[state=3Dstart] > \usemodule[animation] > \starttext > %\startanimation[menu=3Dyes] > %{ > \dorecurse{\udCount} > {\useMPgraphic{foldUD}{num=3D\recurselevel}} > {\useMPgraphic{dotLines}{num=3D\recurselevel}} > %} > %\stopanimation > \stoptext >=20 > 1. Using =E2=80=9CudCount=E2=80=9D doesn=E2=80=99t issue error message, b= ut it draws the path p only. > 2. Using =E2=80=9CudMacro=E2=80=9D issue the error message. >=20 > Is there anything that I miss? You need to call the setglobalmacro(...) macro. The code inside \startMPini= tializations is only executed when you call any MP environment. But you are= using \udCount before \useMPgraphic. A simple solution is to run dummy MP = code so that MP initializations are run: \starttext \setbox\scratchbox\hbox{\startMPcode draw unitcircle; \stopMPcode} \dorecurse{\udCount} {\useMPgraphic{foldUD}{num=3D\recurselevel}} {\useMPgraphic{dotLines}{num=3D\recurselevel}} \stoptext Aditya --8323329-1559906599-1624505943=:827465 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== --8323329-1559906599-1624505943=:827465--