animation using \startuseMPgraphic
Dear all, I am trying to make an animation using the animation module. But it draws 10 figures instead of creating animation. Is there anything I have to do more? Or, is there a better way to do this? Thank you for reading. Best regards, Dalyoung \startuseMPgraphic{inversionPoint}{n} vardef findPointD(expr C, Q, r) = numeric dist, ang; pair X, Y; dist := r**2/sqrt((xpart Q - xpart C)**2 + (ypart Q - ypart C)**2); ang := angle(Q - C); Y := C + dir(ang)*dist; Y enddef; numeric radius, now, move; pair A,B,C,P,Q; path p,q; radius := 2cm; C := origin; p := fullcircle scaled (2*radius); z[1] = point 6 of p; z[2] = point .8 of p; q := (1.5*z1 - .5*z2) -- (-.5z1 + 1.5*z2); %q := fullcircle scaled radius shifted (2cm, 1cm); draw p; draw q; %for i := 0 step 0.1 until 1: move := 0.1; now := move*\MPvar{n}; P := point now along q; Q := findPointD(C, P, radius); drawdot P; drawdot Q withcolor .625red; dotlabel.lft(textext("P"),P); dotlabel.rt(textext("Q"),Q) withcolor .625red; %endfor; \stopuseMPgraphic \usemodule[animation] \setupinteraction[state=start] \starttext %\startplacefigure[] \startanimation[menu=yes] \dorecurse{10}{ \useMPgraphic{inversionPoint}{n=\recurselevel} } \stopanimation %\stopplacefigure \stoptext
Jeong Dal schrieb am 19.04.2020 um 07:08:
Dear all,
I am trying to make an animation using the animation module. But it draws 10 figures instead of creating animation. Is there anything I have to do more?
You have to put each animation step in a frame environment. I recommend also to set the boundingbox to the same size for each frame, otherwise your graphic jumps around. When you use \recurselevel you have to use this: \startanimation[menu=yes] \dorecurse{10} {\startexpanded \startframe \useMPgraphic{inversionPoint}{n=\recurselevel}% \stopframe \stopexpanded} \stopanimation or use #1 to access the counter level and get rid of \startexpanded: \startanimation[menu=yes] \dorecurse{10} {\startframe \useMPgraphic{inversionPoint}{n=#1}% \stopframe} \stopanimation Wolfgang
Dear Wolfgang, Thank you for your help. It works fine. As you said, I need to use boundingbox for stable animation. Thank you again. Best regards, Dalyoung
2020. 4. 19. 오후 4:19, Wolfgang Schuster
작성: Jeong Dal schrieb am 19.04.2020 um 07:08:
Dear all, I am trying to make an animation using the animation module. But it draws 10 figures instead of creating animation. Is there anything I have to do more?
You have to put each animation step in a frame environment. I recommend also to set the boundingbox to the same size for each frame, otherwise your graphic jumps around.
When you use \recurselevel you have to use this:
\startanimation[menu=yes] \dorecurse{10} {\startexpanded \startframe \useMPgraphic{inversionPoint}{n=\recurselevel}% \stopframe \stopexpanded} \stopanimation
or use #1 to access the counter level and get rid of \startexpanded:
\startanimation[menu=yes] \dorecurse{10} {\startframe \useMPgraphic{inversionPoint}{n=#1}% \stopframe} \stopanimation
Wolfgang
Dear Wolfgang, I’d like to ask you one more. To make an animation, almost same graphics are drawn repeatedly. In my code, for example, The base figure(two circles, line, boundingbox) is fixed and only points are moved. But it draws the base figure every time and it is not inefficient. Is there a way to draw the base figure once, and draw the points only at each frame? Thank you. Best regards, Dalyoung \startuseMPgraphic{inversionPoint}{n} vardef findPointD(expr C, Q, r) = numeric dist, ang; pair X, Y; dist := r**2/sqrt((xpart Q - xpart C)**2 + (ypart Q - ypart C)**2); ang := angle(Q - C); Y := C + dir(ang)*dist; Y enddef; numeric radius, now, move; pair A,B,C,P,Q; path p,q; radius := 2cm; C := origin; p := fullcircle scaled (2*radius); z[1] = point 6 of p; z[2] = point .8 of p; q := (1.5*z1 - .5*z2) -- (-.5z1 + 1.5*z2); %q := fullcircle scaled radius shifted (2cm, 1cm); draw p; draw q; % end of base figure % draw points move := 0.1; now := move*\MPvar{n}; P := point now along q; Q := findPointD(C, P, radius); drawdot P; drawdot Q withcolor .625red; dotlabel.lft(textext("P"),P); dotlabel.rt(textext("Q"),Q) withcolor .625red; \stopuseMPgraphic
On 4/19/2020 9:02 PM, Jeong Dal wrote:
Dear Wolfgang,
I’d like to ask you one more.
To make an animation, almost same graphics are drawn repeatedly. In my code, for example, The base figure(two circles, line, boundingbox) is fixed and only points are moved. But it draws the base figure every time and it is not inefficient.
In what sense? Runtime? Even moving the definitions doesn't really save cpu cycles. MP runtime is normally not the bottleneck in a run. \startMPextensions vardef findPointD(expr C, Q, r) = numeric dist, ang; pair X, Y; dist := r**2/sqrt((xpart Q - xpart C)**2 + (ypart Q - ypart C)**2); ang := angle(Q - C); Y := C + dir(ang)*dist; Y enddef; \stopMPextensions
Is there a way to draw the base figure once, and draw the points only at each frame? I guess you could stack them on top of a base background image but I wonder if it's worth the trouble.
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 -----------------------------------------------------------------
Dear Aditya, Thank you for your link. It is good to see your nice code. I’ll see how to apply \startMPanimation … \stopMPanimation to my sample. Thank you again. Best regards, Dalyoung
On Sun, 19 Apr 2020, Jeong Dal wrote:
Dear all,
I am trying to make an animation using the animation module. But it draws 10 figures instead of creating animation. Is there anything I have to do more? Or, is there a better way to do this?
Thank you for reading.
Best regards,
Dalyoung
\startuseMPgraphic{inversionPoint}{n} vardef findPointD(expr C, Q, r) = numeric dist, ang; pair X, Y; dist := r**2/sqrt((xpart Q - xpart C)**2 + (ypart Q - ypart C)**2); ang := angle(Q - C); Y := C + dir(ang)*dist; Y enddef; numeric radius, now, move; pair A,B,C,P,Q; path p,q;
radius := 2cm; C := origin; p := fullcircle scaled (2*radius); z[1] = point 6 of p; z[2] = point .8 of p;
q := (1.5*z1 - .5*z2) -- (-.5z1 + 1.5*z2); %q := fullcircle scaled radius shifted (2cm, 1cm); draw p; draw q; %for i := 0 step 0.1 until 1: move := 0.1; now := move*\MPvar{n}; P := point now along q; Q := findPointD(C, P, radius); drawdot P; drawdot Q withcolor .625red; dotlabel.lft(textext("P"),P); dotlabel.rt(textext("Q"),Q) withcolor .625red; %endfor; \stopuseMPgraphic
\usemodule[animation] \setupinteraction[state=start]
\starttext %\startplacefigure[] \startanimation[menu=yes] \dorecurse{10}{ \useMPgraphic{inversionPoint}{n=\recurselevel} } \stopanimation %\stopplacefigure \stoptext
Also see my simple wrapper around this: https://adityam.github.io/context-blog/post/metapost-animation/ Aditya
participants (4)
-
Aditya Mahajan
-
Hans Hagen
-
Jeong Dal
-
Wolfgang Schuster