
Hi,
On Sat, Jul 19, 2025 at 2:42 AM Jeong Dal via ntg-context
Dear all,
I tried to make an animation which draws Cardioid curve. I found a code which draws Cardioid using circles. Since I’d like to draw it differently, I modified it a little.
1. Define the z[] values in the \startMPdefinitions block 2. Modified the drawing method in \startMPbuffer
When I run it, it doesn’t recognize the z[] values defined already. I think that the z[] values are not delivered to \startbuffer. I tried \startMPinclusions, \startMPinitialization, but I couldn’t succeed.
1. How can I deliver the z[] values into the buffer? 2. What is wrong in the following code?
Thank you for reading.
Best regards,
Dalyoung
\usemodule[animation] \setupinteraction[state=start]
\startMPdefinitions%{Cardioid} path p,q; numeric u, ang,j,num; picture pict;
u := 1cm; ang := 360/52;
p := fullcircle scaled 5u; for i=0 upto 51: z[i] = 2.5*dir(ang*i)*u; endfor; pict := image ( draw p withpen pencircle scaled 1; ); \stopMPdefinitions
\startbuffer[Cardioid][s] draw pict; num := \MPrawvar{Cardioid}{s};
for i = 0 upto num: j := 2i mod 52; draw z[i] -- z[j]; endfor; setbounds currentpicture to boundingbox currentpicture enlarged 2mm ; \stopbuffer
\startdocument
\startanimation[menu=yes, framerate=7] \dorecurse{52} {\startexpanded \startframe \setupMPvariables[Cardioid][s=\recurselevel] \processMPbuffer[Cardioid] \stopframe \stopexpanded} \stopanimation \stopdocument
I don't have the animation module, so maybe I miss the point, but the code below at least compiles and gives something that could be what you are looking for. If not, sorry for the noise. % \usemodule[animation] \setupinteraction[state=start] \startMPinitializations% CHANGED path p,q; numeric u, ang,j,num; picture pict; u := 1cm; ang := 360/52; p := fullcircle scaled 5u; for i=0 upto 51: z[i] = 2.5*dir(ang*i)*u; endfor; z[52]=z[0] ; % NEW pict := image ( draw p withpen pencircle scaled 1; ); \stopMPinitializations% CHANGED \startbuffer[Cardioid][s] draw pict; num := \MPrawvar{Cardioid}{s}; for i = 0 upto num: j := 2i mod 52; draw z[i] -- z[j]; endfor; setbounds currentpicture to boundingbox currentpicture enlarged 2mm ; \stopbuffer \startdocument % \startanimation[menu=yes, framerate=7] \dorecurse{52} {%\startexpanded \startframed \setupMPvariables[Cardioid][s=\recurselevel] \processMPbuffer[Cardioid] \stopframed %\stopexpanded } % \stopanimation \stopdocument /Mikael