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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to