Yes, in Asymptote there are so-called anonymous functions (see here, page 290) can be created with the keyword new
, so that function definition in your example could be simplified without using programming tricks (you are difficult ^^ your trick is quite comfortable!).
size(5cm);
import graph;
import contour;
typedef real function(real, real);
function f(real d) {
return new real(real x, real y) {
return x^2 + y^2 -1+ d*x^2*y^2;
};
}
pen[] c={red, blue,purple,orange}; c.cyclic=true; // for different Edwards curves
for(int d=100; d > 0; d -= 10) {
guide[][] thegraphs = contour(f(d), a=(-2,-2), b=(2,2), new real[] {0},nx=200,operator..);
// nx=200 >>> for larger sample (default nx=100,ny=nx)
// operator.. >>> smoother join
draw(thegraphs[0],c[d]);
}
shipout(bbox(5mm,invisible));
I hope you can adapt this to your animation. By the way, I am very impressive with recently-discovered Edwards curves and their application in cryptography.
Asymptote is rich in mathematical flavor!
Update Animation version
// x.asy >>> x.pdf >>> making GIF ưith ImageMagick command in the command line window
// magick -density 200 x.pdf -alpha remove x.gif
unitsize(2cm);
import contour;
import animate;
typedef real function(real, real);
function f(real d) {
return new real(real x, real y) {
return x^2 + y^2 -1+ d*x^2*y^2;
};
}
real a=1.25;
draw(box((a,a),(-a,-a)),invisible);
draw((a,0)--(-a,0)^^(0,a)--(0,-a),gray);
animation A;
for(real d=360; d > -1; d -= 5) {
save();
guide[][] Edwards = contour(f(d), a=(-1,-1), b=(1,1), new real[] {0},nx=200,operator..);
draw(Edwards[0],blue);
label("$d = $ "+string(d),(-a+.2, -a+.2),align=E);
A.add();
restore();
}
erase();
A.movie();