From: Jeong Dal <haksan@me.com>
To: "list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
ntg-context@ntg.nl" <ntg-context@ntg.nl>
Subject: Re: simplifying repeated macro calls in metafun
Date: Thu, 24 Jun 2021 05:26:25 +0900 [thread overview]
Message-ID: <804761E2-A68A-463F-9182-EE11D13D8850@me.com> (raw)
In-Reply-To: <mailman.1145.1624377609.1130.ntg-context@ntg.nl>
[-- Attachment #1.1: Type: text/plain, Size: 5393 bytes --]
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…
>
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:=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;
setbounds currentpicture to boundingbox q;
enddef;
def linesUD(expr i) =
draw p;
draw z0 for k=0 upto i+1: --z[k] endfor dashed evenly;
setbounds currentpicture to boundingbox q;
enddef;
\stopbuffer
\startbuffer[UDpts]
ang := 40;
z[1] = whatever[z[0], z[0]+dir(ang)*u] = whatever[A,B];
G := 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;
\stopbuffer
\startbuffer[UD0]
draw p;
setbounds currentpicture to boundingbox q;
\stopbuffer
\startbuffer[UD1]
grayUD(0);
\stopbuffer
\startbuffer[UD11]
linesUD(0);
\stopbuffer
\startbuffer[UD2]
G := z0;
grayUD(1)
\stopbuffer
\startbuffer[UD21]
linesUD(1);
\stopbuffer
\startbuffer[UD3]
G := z1;
grayUD(2);
\stopbuffer
\startbuffer[UD31]
linesUD(2);
\stopbuffer
\startbuffer[UD4]
G := z2;
grayUD(3);
\stopbuffer
\startbuffer[UD41]
linesUD(3);
\stopbuffer
\startbuffer[UD5]
G := 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=start]
\usemodule[animation]
\starttext
\startanimation[menu=yes]
{\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’t the correct result yet.
Using \startuseMPgraphic, and \dorecurse, the code is simpler. But, it seems to me that \startanimation … \stopanimation is not working with \dorecurse{}{} …
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:=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;
\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{7}
{
{\useMPgraphic{foldUD}{num=\recurselevel}}
{\useMPgraphic{dotLines}{num=\recurselevel}}
}
\stopanimation
\stoptext
Best regards,
Dalyoung
[-- Attachment #1.2: Type: text/html, Size: 44998 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
___________________________________________________________________________________
next parent reply other threads:[~2021-06-23 20:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1145.1624377609.1130.ntg-context@ntg.nl>
2021-06-23 20:26 ` Jeong Dal [this message]
2021-06-24 3:31 ` Aditya Mahajan
2021-06-24 3:42 ` Aditya Mahajan
2021-06-24 7:16 ` Hans Hagen
[not found] <mailman.47.1624523134.1143.ntg-context@ntg.nl>
2021-06-25 19:14 ` Jeong Dal
[not found] <mailman.1069.1624285904.1130.ntg-context@ntg.nl>
2021-06-21 21:50 ` Jeong Dal
2021-06-22 13:49 ` Otared Kavian
2021-06-22 16:00 ` Wolfgang Schuster
[not found] <mailman.1.1624183201.7245.ntg-context@ntg.nl>
2021-06-20 23:30 ` Jeong Dal
2021-06-21 4:26 ` Aditya Mahajan
2021-06-21 12:07 ` Otared Kavian
2021-06-21 12:21 ` Mikael Sundqvist
2021-06-21 14:31 ` Otared Kavian
2021-06-21 18:35 ` Mikael Sundqvist
2021-06-21 13:34 ` Jeong Dal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=804761E2-A68A-463F-9182-EE11D13D8850@me.com \
--to=haksan@me.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).