* Delivering the value of a variable in MetaFun to ConTeXt [not found] <mailman.1186.1624441651.1130.ntg-context@ntg.nl> @ 2021-06-23 20:00 ` Jeong Dal 2021-06-23 20:36 ` Hans Hagen 0 siblings, 1 reply; 6+ messages in thread From: Jeong Dal @ 2021-06-23 20:00 UTC (permalink / raw) To: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl Hi, Is there a way to deliver the value of a variable in MetaFun to ConTeXt. For example, I want to do the following: \starttext \startMPcode numeric maxCount; % … some code maxCount := 10; \stopMPcode dorecurse{maxCount} {It is \recurselevel.\par} \stoptext Thank you for reading. Best regards, Dalyoung ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Delivering the value of a variable in MetaFun to ConTeXt 2021-06-23 20:00 ` Delivering the value of a variable in MetaFun to ConTeXt Jeong Dal @ 2021-06-23 20:36 ` Hans Hagen 2021-06-24 2:33 ` Jeong Dal 0 siblings, 1 reply; 6+ messages in thread From: Hans Hagen @ 2021-06-23 20:36 UTC (permalink / raw) To: mailing list for ConTeXt users, Jeong Dal On 6/23/2021 10:00 PM, Jeong Dal wrote: > > Hi, > > Is there a way to deliver the value of a variable in MetaFun to ConTeXt. > For example, I want to do the following: > > \starttext > \startMPcode > numeric maxCount; > % … some code > maxCount := 10; > \stopMPcode > > dorecurse{maxCount} > {It is \recurselevel.\par} > > \stoptext > > Thank you for reading. \newcount\MyCount \starttext \startMPcode numeric maxCount; maxCount := 10; setglobalmacro("MyMacro",decimal maxCount); setglobalcount("MyCount",maxCount); \stopMPcode \dorecurse{\MyMacro}{It is \recurselevel. }\par \dorecurse{\MyCount}{It is \recurselevel. }\par \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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Delivering the value of a variable in MetaFun to ConTeXt 2021-06-23 20:36 ` Hans Hagen @ 2021-06-24 2:33 ` Jeong Dal 2021-06-24 3:39 ` Aditya Mahajan 0 siblings, 1 reply; 6+ messages in thread From: Jeong Dal @ 2021-06-24 2:33 UTC (permalink / raw) To: Hans Hagen; +Cc: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 3528 bytes --] Dear Hans, Your code works fine. > \starttext > > \startMPcode > numeric maxCount; > maxCount := 10; > setglobalmacro("MyMacro",decial maxCount); > setglobalcount("MyCount",maxCount); > \stopMPcode > > > \dorecurse{\MyMacro}{It is \recurselevel. }\par > \dorecurse{\MyCount}{It is \recurselevel. }\par > > \stoptext I applied your method to my code as following. \newcount\udCount %%% add count \startMPinitializations%{UDBasic} pair A,B,C,D; pair E, F, G, H; path p,q; numeric ang,maxNum; numeric n; %AM Added u:=1in; A=(.95*TextWidth,u); B=(0,u); C=(0,0); D=(.95*TextWidth,0); p := A--B--C--D; q := (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle; z0=(.1u,0); vardef nextPt (expr M,N) = if ypart(N) = 0: H := whatever[N, N + dir(.5*angle(M-N))*u] = whatever[A,B]; else: H := whatever[N, N + dir(.5*angle(M-N))*u] = whatever[C,D]; fi; H enddef; def grayUD(expr i) = draw G -- if ypart(B)=ypart(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=0 upto i: --z[k] endfor dashed evenly; clip currentpicture to q; enddef; def linesUD(expr i) = draw p; draw z0 for k=0 upto i+1: --z[k] endfor dashed evenly; % AM: removed. Set in in the main code % setbounds currentpicture to boundingbox q; enddef; ang := 40; z[1] = whatever[z[0], z[0]+dir(ang)*u] = whatever[A,B]; % AM: Changed next line from G to z[-1] z[-1] = whatever[z[0], z[0]+dir(2*ang)*u] = whatever[A,B]; for k = 2 upto 20: z[k] = nextPt(z[k-2],z[k-1]); maxNum := k; exitif xpart(z[k]) > TextWidth; endfor; maxNum := maxNum-1; setglobalmacro("udMacro",decimal maxNum); %%% define udMacro and udCount setglobalcount("udCount",maxNum); \stopMPinitializations \startuseMPgraphic{foldUD}{num} numeric n; n := \MPvar{num}-1; G := z[n-1]; grayUD(n); \stopuseMPgraphic \startuseMPgraphic{dotLines}{num} numeric n; n := \MPvar{num}-1; linesUD(n); \stopuseMPgraphic \setupinteraction[state=start] \usemodule[animation] \starttext %\startanimation[menu=yes] %{ \dorecurse{\udCount} {\useMPgraphic{foldUD}{num=\recurselevel}} {\useMPgraphic{dotLines}{num=\recurselevel}} %} %\stopanimation \stoptext 1. Using “udCount” doesn’t issue error message, but it draws the path p only. 2. Using “udMacro” issue the error message. Is there anything that I miss? Best regards, Dalyoung ********** tex error > tex error on line 75 in file /Users/graph/Library/Mobile Documents/com~apple~CloudDocs/texMain/funmath/foldBandMPnew.tex: Undefined control sequence <argument> \udMacro <macro> \dorecurse #1->\ifcase #1 \relax \expandafter \gobbletwoarguments \or \expandafter \syst_helpers_recurse_y \else \expandafter \syst_helpers_recurse_x \fi {#1} <line 3.75> \dorecurse{\udMacro} 65 numeric n; 66 n := \MPvar{num}-1; 67 linesUD(n); 68 \stopuseMPgraphic 69 70 \setupinteraction[state=start] 71 \usemodule[animation] 72 \starttext 73 %\startanimation[menu=yes] 74 %{ 75 >> \dorecurse{\udMacro} 76 {\useMPgraphic{foldUD}{num=\recurselevel}} 77 {\useMPgraphic{dotLines}{num=\recurselevel}} 78 %} [-- Attachment #1.2: Type: text/html, Size: 36066 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Delivering the value of a variable in MetaFun to ConTeXt 2021-06-24 2:33 ` Jeong Dal @ 2021-06-24 3:39 ` Aditya Mahajan 2021-06-24 6:31 ` Hans Hagen 0 siblings, 1 reply; 6+ messages in thread From: Aditya Mahajan @ 2021-06-24 3:39 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1: Type: text/plain, Size: 3445 bytes --] On Thu, 24 Jun 2021, Jeong Dal wrote: > Dear Hans, > > Your code works fine. > > > \starttext > > > > \startMPcode > > numeric maxCount; > > maxCount := 10; > > setglobalmacro("MyMacro",decial maxCount); > > setglobalcount("MyCount",maxCount); > > \stopMPcode > > > > > > \dorecurse{\MyMacro}{It is \recurselevel. }\par > > \dorecurse{\MyCount}{It is \recurselevel. }\par > > > > \stoptext > > I applied your method to my code as following. > > \newcount\udCount %%% add count > \startMPinitializations%{UDBasic} > pair A,B,C,D; > pair E, F, G, H; > path p,q; > numeric ang,maxNum; > > numeric n; %AM Added > > u:=1in; > A=(.95*TextWidth,u); B=(0,u); C=(0,0); D=(.95*TextWidth,0); > p := A--B--C--D; > q := (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle; > z0=(.1u,0); > > vardef nextPt (expr M,N) = > if ypart(N) = 0: > H := whatever[N, N + dir(.5*angle(M-N))*u] = whatever[A,B]; > else: > H := whatever[N, N + dir(.5*angle(M-N))*u] = whatever[C,D]; > fi; > H > enddef; > > def grayUD(expr i) = > draw G -- if ypart(B)=ypart(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=0 upto i: --z[k] endfor dashed evenly; > clip currentpicture to q; > enddef; > > def linesUD(expr i) = > draw p; > draw z0 for k=0 upto i+1: --z[k] endfor dashed evenly; > > % AM: removed. Set in in the main code > % setbounds currentpicture to boundingbox q; > enddef; > > ang := 40; > z[1] = whatever[z[0], z[0]+dir(ang)*u] = whatever[A,B]; > > % AM: Changed next line from G to z[-1] > z[-1] = whatever[z[0], z[0]+dir(2*ang)*u] = whatever[A,B]; > for k = 2 upto 20: > z[k] = nextPt(z[k-2],z[k-1]); > maxNum := k; > exitif xpart(z[k]) > TextWidth; > endfor; > maxNum := maxNum-1; > setglobalmacro("udMacro",decimal maxNum); %%% define udMacro and udCount > setglobalcount("udCount",maxNum); > > \stopMPinitializations > > \startuseMPgraphic{foldUD}{num} > numeric n; > n := \MPvar{num}-1; > G := z[n-1]; > grayUD(n); > \stopuseMPgraphic > \startuseMPgraphic{dotLines}{num} > numeric n; > n := \MPvar{num}-1; > linesUD(n); > \stopuseMPgraphic > > \setupinteraction[state=start] > \usemodule[animation] > \starttext > %\startanimation[menu=yes] > %{ > \dorecurse{\udCount} > {\useMPgraphic{foldUD}{num=\recurselevel}} > {\useMPgraphic{dotLines}{num=\recurselevel}} > %} > %\stopanimation > \stoptext > > 1. Using “udCount” doesn’t issue error message, but it draws the path p only. > 2. Using “udMacro” issue the error message. > > Is there anything that I miss? You need to call the setglobalmacro(...) macro. The code inside \startMPinitializations 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=\recurselevel}} {\useMPgraphic{dotLines}{num=\recurselevel}} \stoptext Aditya [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Delivering the value of a variable in MetaFun to ConTeXt 2021-06-24 3:39 ` Aditya Mahajan @ 2021-06-24 6:31 ` Hans Hagen 0 siblings, 0 replies; 6+ messages in thread From: Hans Hagen @ 2021-06-24 6:31 UTC (permalink / raw) To: mailing list for ConTeXt users, Aditya Mahajan On 6/24/2021 5:39 AM, Aditya Mahajan wrote: > You need to call the setglobalmacro(...) macro. The code inside \startMPinitializations 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=\recurselevel}} > {\useMPgraphic{dotLines}{num=\recurselevel}} > \stoptext A run with no sideeffects in the content stream is: \startMPcalculation .... \stopMPcalculation 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.47.1624523134.1143.ntg-context@ntg.nl>]
* Re: Delivering the value of a variable in MetaFun to ConTeXt [not found] <mailman.47.1624523134.1143.ntg-context@ntg.nl> @ 2021-06-25 19:45 ` Jeong Dal 0 siblings, 0 replies; 6+ messages in thread From: Jeong Dal @ 2021-06-25 19:45 UTC (permalink / raw) To: ntg-context [-- Attachment #1.1: Type: text/plain, Size: 653 bytes --] Dear Aditya and Hans, Thank you for your suggestion. I add > \startMPcalculation > .... > \stopMPcalculation and it works. \setupinteraction[state=start] \usemodule[animation] \starttext %\startanimation[menu=yes] %{ \startMPcalculation path p; \stopMPcalculation \dorecurse{\udCount} {\useMPgraphic{foldUD}{num=\recurselevel}} {\useMPgraphic{dotLines}{num=\recurselevel}} %} %\stopanimation \stoptext However, it draws all the figures under the \startanimation case. There may be something I missed or there is something uncertain between \dorecurse and \startanimation. Thank you. Best regards, Dalyoung [-- Attachment #1.2: Type: text/html, Size: 3638 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-25 19:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <mailman.1186.1624441651.1130.ntg-context@ntg.nl> 2021-06-23 20:00 ` Delivering the value of a variable in MetaFun to ConTeXt Jeong Dal 2021-06-23 20:36 ` Hans Hagen 2021-06-24 2:33 ` Jeong Dal 2021-06-24 3:39 ` Aditya Mahajan 2021-06-24 6:31 ` Hans Hagen [not found] <mailman.47.1624523134.1143.ntg-context@ntg.nl> 2021-06-25 19:45 ` Jeong Dal
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).