Animation in Asymptote

Copied from my blog in order to create another Russian-language source of information on this topic.



Hello! When I, in the process of mastering the Asymptote program, which took place as I learned the nuances of the settings for this program described here in this hub , fully mastered the processing of .asy files in which there is no animation, I naturally ran into the animation.



Spoiler heading
Give animation to the masses!



Fortunately, for this, in the case of the .pdf output format, none of the additional programs described by me in the hub using the link above, after the ghostscript program, needs to be uninstalled, and even the devil knows how long it was digging. But then I did not know about it, which complicated the matter many times. You process the wheel.asy file and what? Well, .pdf appeared during processing in TeXworks (see the link given above) in the same folder with the processed .asy file, and when opened in Explorer (see the same hub), in the C:\Windows\System32



. So what? There was no animation in it and that’s it, even though you crack. And before animation in Asymptote, I learned how to make animations in tikz and pstricks . So I didn’t succeed until I deleted the animate.sty file from the C:\Program Files\MiKTeX 2.9\tex\latex\animate



folder and put the file with the same name downloaded later. There he is . Thus, knowing that this the package works with tikz and pstricks, I was inclined to think that it doesn’t work out for me, most likely, not because of problems with TeX, but for some other reason. So I searched the Old Internet for several years. At first I searched in IE browser, well, there is no convenient translator there. Then I sniffed that Google has a convenient translator in it. Also searched, searched, searched, searched, until he came across this page. It turned out that for some reason in all .asy files from the C:\Program Files\Asymptote\examples\animations



folder, to get from them .pdf with animation, there is not enough single line



 settings.twice=true;
      
      





I added this line to the wheel.asy file from the animation folder of the examples folder:



Finally animation !!!!!!!
 import graph; // Uncomment the following 2 lines to support pdf animations: usepackage("animate"); settings.tex="pdflatex"; settings.twice=true; import animation; size(0,200); defaultpen(3); dotfactor=4; pair wheelpoint(real t) { return (t+cos(t),-sin(t)); } guide wheel(guide g=nullpath, real a, real b, int n) { real width=(ba)/n; for(int i=0; i <= n; ++i) { real t=a+width*i; g=g--wheelpoint(t); } return g; } real t1=0; real t2=t1+2*pi; animation a; draw(circle((0,0),1)); draw(wheel(t1,t2,100),linetype("0 2")); yequals(Label("$y=-1$",1.0),-1,extend=true,linetype("4 4")); xaxis(Label("$x$",align=3SW),0); yaxis("$y$",0,1.2); pair z1=wheelpoint(t1); pair z2=wheelpoint(t2); dot(z1); dot(z2); int n=10; real dt=(t2-t1)/n; for(int i=0; i <= n; ++i) { save(); real t=t1+dt*i; draw(circle((t,0),1),red); dot(wheelpoint(t)); a.add(); // Add currentpicture to animation. restore(); } erase(); // Merge the images into a gif animation. //a.movie(BBox(0.25cm),loops=10,delay=250); // Merge the images into a pdf animation. label(a.pdf(BBox(0.25cm),delay=250,"controls",multipage=false));
      
      







At the same time, in order to receive .pdf, knowing 300 words in English, I realized that I need to uncomment in the form of the wheel.asy file in which the user gets it from the author (s) of Asymptote program, 2 lines:



 ....................... usepackage("animate"); settings.tex="pdflatex"; .......................
      
      





Looking at the comments on these lines at the end of the wheel.asy file:



 ........................ // Merge the images into a gif animation. a.movie(BBox(0.25cm),loops=10,delay=250); // Merge the images into a pdf animation. // label(a.pdf(BBox(0.25cm),delay=250,"controls",multipage=false));
      
      





, I realized that to get .pdf I need to redo the code that I got from the authors of the program and comment out the line



 a.movie(BBox(0.25cm),loops=10,delay=250);
      
      





, and uncomment the line



 label(a.pdf(BBox(0.25cm),delay=250,"controls",multipage=false));
      
      





And how my wheel rolled after these gestures! The logic of the Asymptote program authors is also unclear: to get .gif one extra program is needed more than to get .pdf. Files with examples will most likely be watched by users who do not know how to do this at all. Well, do this so that when these users open these files immediately, without changing anything in them, they can receive an output format that requires fewer additional programs - .pdf, no, they made .gif. What for?? Anyway. Yes, I’ll also note that when you open the wheel.asy file in Explorer (see my hub ) to get a working .gif out of it, the presence of the config.asy file in the same folder with it (see my hub ) is optional. Let me remind you that .gif in this case (when opened in Explorer) is formed in the C:\Windows\System32



. When processing this .asy file in TeXworks, the presence of config.asy in the same folder as the file to be processed is mandatory (or including the lines that I mentioned in the previous link directly into the processed .asy file itself). Well, here it is. I got this rolling wheel Straight, I laughed all over, delighted. It was at night. I went to bed. Woke up and for the comp. While the computer turned on, he sat, rubbing his hands. Well, I think, now I’ll mathematically pay for oil fuel oil). Yeah, right now. The animations from the subfolder of examples succeeded practically everything, except for embeddedmovie.asy, externalmovie.asy and embeddedu3d.asy. I waited for the first 2 files later, but it didn’t work with the last one: there, as I understand it, some dice.u3d file needs to be downloaded from somewhere else, and which one is a big secret for a small company. Well, that, "Oh, the kingdom is not enough, there is no place to roam." I wrote, there was such a code:



 settings.twice=true; usepackage("animate"); import solids; settings.tex="pdflatex"; import animation; settings.outformat="pdf"; settings.axes3=true; import graph3; import palette; currentprojection=orthographic(1,1,1); limits((-1.3,-1.3,-1.3),(1.3,1.3,1.3)); unitsize(6cm); animation a; int n=44; for(int i=0; i<=n; ++i){ real g(real x) {return sqrt(1-x^2);} pair G(real x) {return (x,g(x));} triple G3(real x) {return (x,g(x),0);} path q=graph(G,1-i/n,1); path3 q3=path3(q); revolution c=revolution(q3,X,0,360); draw(surface(c),red); real f(real x) {return sqrt(1-x^2);} pair F(real x) {return (x,f(x));} triple F3(real x) {return (x,f(x),0);} path p=graph(F,-1,-1+i/n); path3 p3=path3(p); revolution b=revolution(p3,X,0,360); draw(surface(b),green); axes3("$x$","$y$","$z$",Arrow3); a.add(); restore(); } erase(); label(a.pdf("controls,loop",delay=1000));
      
      





I received the following promising error in TeXworks :



 error: out of memory
      
      





When opening this .asy file in Explorer (see the link to the hub just above) the error was the same. Yeah. I’ve steamed, I’ve steamed, I’ve muddied, I found that when n=3 it turns out .pdf with animation, but already at n=4 that this error also arises. Let me ask at the Asymptote forum itself . But Anglo-Saxons are law-abiding people who do not like to backtrack from instructions. They did not come up with anything. What to do? Was it worth shoveling half the Internet to stumble on such garbage? Well, nothing, the Russians don’t give up! And besides, normal heroes always go around ... I began to observe the process of processing the wheel.asy file in TeXworks and what did I see? First, the files _wheel + 0.pdf, _wheel + 1.pdf, ..., _wheel + 10.pdf appear, then from these files a multi-page file _wheel.pdf is formed and further on the program. And in order to do all this, the animation module is imported into the .asy file from which they are going to get the animation . And then I had an idea. But what if in this module (file C:\Program Files\Asymptote\animation.asy



) you find a place that generates files like _wheel + 0.pdf and turn it off? Do you stamp these files with Asymptote processing .asy files generated by loop bypass in the batch file? These .asy files can be made to be created with the names + 0.asy , name + 1.asy , and so on, as long as necessary. Where the name is some set of Latin letters associated with the animation being created, which you most likely want to change on the ready-made pdf with animation. But it will be later. In the meantime, after creating the files, the name is + 0.asy , the name is + 1.asy ... according to my idea, they should be processed by Asymptote. This would create files name + 0.pdf , name + 1.pdf ... And before the code that creates the files name + 0.asy , name + 1.asy ..., I had to insert lines in the batch file to create the file name.asy or rather, just lines to enter into this file. And the file name.asy would be formed simply as a result of the batch file. In this file, the name is .asy, I was planning to import the animation module that I remade instead of the animation module itself. I decided to make the beginning of this file name.asy the simplest, in the spirit of the beginning of the wheel.asy file. After the loop, I just stupidly copied the lines from this file and pasted them into the batch file like this:



 echo  >> .asy
      
      





,



 echo  >> .asy
      
      





I wrote a batch file so that in the created file the name. Easy, the body of the loop was empty, and where for was, it would turn out like this:



 for(int i=0; i <= n; ++i) {
      
      





In the batch file, the line above the line of code entering this line into the file name. Easy is the line



 echo int n=%n%; >>%name%.asy
      
      





, and the third and fourth lines of this batch file are:

 set n=24 set name=OdnopGip
      
      





, so by the beginning of the loop in the file name. Easy Asymptote already knows the value of n in this case and everything works. The environment variable name means, in translation into the language of this article, the name from name.asy . Declaring in this case the values ​​of name or n in the batch file via set seems to me extremely convenient: changing their values ​​in only one place in the batch file entails changing all the names of .tex, .pdf files that are generated when processing a certain .asy file or number frames in the resulting animated pdf, essentially changing the details of the animation. Well, here it is. So I prepared the frames name + 0.pdf , name + 1.pdf ..., however, since after opening each frame it opened, I had to include a command in my batch file to close it. Since I didn’t know how to close a window with a specific title from a batch file, I included the following command in my batch file in the body of the frame-blank processing cycle .asy:

 taskkill /IM AcroRd32.exe
      
      





, which, as it turned out later in the process of running all this, is even better than closing each specific frame: sometimes the frame still does not have time to appear on the monitor, and the processing of the next .asy file begins, after which the next frame appears on the monitor, and the final the team from this next step of the cycle will close both the frame from this next step and the frame of the previous step, past which the (running) batch file ran, although it is clear that after including this command in the batch file during its execution of the book in .pdf, it’s no longer melt, that's bad, yes. Further along the logic, I needed to rename the files name + 0.asy, name + 1.asy, ... to _name + 0.asy, _name + 1.asy, ..., since the presence of files with exactly these names in one the folder with the .asy file being processed, in which there is animation, involves processing this file provided that the native animation module is imported before starting the production of the file name.pdf (yes, I could insert lines of the code that makes up the frame inside the batch file with variable k, not in the file name + k.asy, and the file _name + k.asy, but this would require more input of the character "_". And further processing of Asymptote wounds . E imya.asy file created short, at the original idea was to have a batch file looks like this:



 cd /d %0\.. echo off set n=99 set name=cvetok echo settings.twice=true; > %name%.asy echo usepackage("animate"); >>%name%.asy echo settings.tex="pdflatex"; >>%name%.asy echo import izgraphiki; >>%name%.asy echo animation a; >>%name%.asy echo int n=%n%; >>%name%.asy echo for(int i=0; i ^<= n; ++i) { >>%name%.asy echo a.add(); >>%name%.asy echo restore(); >>%name%.asy echo } >>%name%.asy echo erase(); >>%name%.asy echo label(a.pdf(BBox(0.25cm),delay=250,"controls",multipage=false)); >>%name%.asy for /l %%k in (0,1,%n%) do ( echo import graph; >> %name%+%%k.asy echo settings.tex="pdflatex"; >> %name%+%%k.asy echo limits((-1.2,-1.2^),(1.2,1.2^)^); >> %name%+%%k.asy echo size(0,100^); >> %name%+%%k.asy echo real f(real t^) {return cos(2*t^);} >> %name%+%%k.asy echo path g=polargraph(f,0,2pi*%%k/%n%,operator ..^)--cycle; >> %name%+%%k.asy echo fill(g,green+white^); >> %name%+%%k.asy echo xaxis("$x$",above=true^); >> %name%+%%k.asy echo yaxis("$y$",above=true^); >> %name%+%%k.asy echo draw(g^); >> %name%+%%k.asy ) for /l %%l in (0,1,%n%) do ( asy %name%+%%l.asy taskkill /IM AcroRd32.exe ) for /l %%l in (0,1,%n%) do ( rename %name%+%%l.pdf _%name%+%%l.pdf ) asy %name%.asy
      
      





Here we see that I am importing the animation.asy module I modified above. I gave the plain name izgraphiki.asy to this module. And for the animation .pdf file I get, I did not come up with a name better than cvetok. Apparently, because of the scarcity of his imagination. Well, all right, how it is. I will tell you about “my” izgraphiki.asy module at the very end of this story, so as not to lose the thread of the story now, but for now I’ll note that I try to give this file the name iz-graphiki.asy, and then also try iz + graphiki.asy didn’t lead to the intended goal: the work of my batch file stopped in full swing and did not resume under any circumstances. Apparently, the modules of the Asymptote program should contain only letters of the Latin alphabet. In any case, compliance with this condition certainly will not hurt. So, the work of the batch file I cited above ended with the appearance of a coveted .pdf file with animation from an arbitrarily large one (within reasonable limits, so as not to wait 3 hours, it works, the animated .pdf appears, everything is fine, but the computer has a speed of execution operations are only final). Let me do animated construction of 3d objects. And then another troubles became clear. I managed to stamp shots with these objects, but, oh, that’s it. On these frames, these objects turned out to be rotated in space, everything is fine here, but just because of this presence of volume in pdf frames, they cannot be used to build frames in pdf with animation. Let me think further. Watching the processing of a slightly modified sphere.asy file:



slightly modified sphere.asy file
 settings.twice=true; usepackage("animate"); import solids; settings.tex="pdflatex"; import animation; settings.outformat="pdf"; currentprojection=orthographic((0,5,2)); currentlight=(0,5,5); int nbpts=200; real step=2*pi/nbpts; int angle=90; unitsize(1cm); triple[] P=new triple[nbpts]; for(int i=0; i < nbpts; ++i) { real t=-pi+i*step; P[i]=(3sin(t)*cos(2t),3sin(t)*sin(2t),3cos(t)); } transform3 t=rotate(angle,(0,0,0),(1,0.25,0.25)); revolution r=sphere(O,3); draw(surface(r),lightgrey); draw(r,backpen=linetype("8 8",8)); animation A; for(int phi=0; phi < 360; phi += angle) { bool[] front=new bool[nbpts]; save(); for(int i=0; i < nbpts; ++i) { P[i]=t*P[i]; front[i]=dot(P[i],currentprojection.camera) > 0; } draw(segment(P,front,operator ..),1mm+blue+extendcap); draw(segment(P,!front,operator ..),grey); A.add(); restore(); } label(A.pdf());
      
      







, I noticed that during this processing all frames of the animation appear and do not disappear sequentially, but only they, if I may say so, in the 2d version: in my opinion this is full 3D graphics, but if you try to view them from different sides in the Abode viewer window Reader by moving with the left mouse button pressed, as expected from the 3d graphics obtained using Asymptote, unless the possibility of this consideration is turned off purposefully before starting production of .pdf with animation in a .asy file, then this is impossible th. The names of these 2d frames: _sphere + 0.pdf, _sphere + 1.pdf, ... Having learned about the generation of spatial 2d frames when processing .asy files that have animation of 3d objects, it occurred to me to get .pdf frames from a batch file for further use in processing the .asy file, in which there is a cycle with an empty body, which I generate at the very beginning of the batch file, by processing not just .asy files, but by processing .asy files, each of which has a cycle. These loops in each of these .asy file stubs for receiving a .pdf frame from it I made up of one single frame: I did not make these stubs to get animated .pdf from them, but to get a 2d frame, which occurs simultaneously in the process of processing each of the .asy stub file. In order to receive .asy blank files with such loops, I made it so that in the loops of all the blank files .asy, the variables of these loops at the beginning and end of loops take the same values ​​- 0. The differences between .pdf frames resulting from processing play Asymptote of workpiece files .asy are caused by differences in the bodies of the workpiece file loop cycles.asy, which (differences) are, in turn, due to the introduction of each of the sequential values ​​of the batch file loop variable in the body function of the workpiece file cycle.asy created by the batch file when its variable qi Kla, taking its next value, freezes, waiting for the completion of the creation of the procurement file. Easy, corresponding to this value of the batch file loop variable. In short, these differences are created by the batch file cycle variable. The names of these 2d frames are of the form: name + k + 0.pdf, where, because these 2d frames are the result of changing the batch file cycle variable, k takes values ​​from 0 to the final value of the batch file loop variable with step 1. To get the animated .pdf from the .asy file with the empty body of the loop created by the batch file earlier, the .pdf frame names should look like this: _name + k.pdf. Therefore, the next team in the batch file I renamed these frames-.pdf. I did it in a loop. And finally, the processing team run the Asymptote .asy file with an empty loop body. After this processing, a .pdf with animation appears. In the batch file, after this command, I did not write a command to open the .pdf file with animation, because this opening is assumed by default, this .pdf file with animation opens anyway at the end of this processing, just like a .pdf file opens generated by Asymptote processing a .asy file without animation. If the reader observed the process of processing .asy files from a subfolder with animations of the examples folder located in the Asymptote program folder, then he will understand that part of the name from _name + k.pdf should coincide with the name of the .asy file with an empty body of the loop. The files _name + k.pdf are the result of renaming some other .pdf files (files name + k + 0.pdf), which, in turn, are a by-product of processing some .asy files by the program, so I simplified the task for these files .asy were created by a batch file under the names name + 0.asy, name + 1.asy, ... So, well, I described the principle of work of a batch file that I planned, it's time to give an example of one of such batch files. For example, this:



 cd /d %0\.. echo off set n=44 echo settings.twice=true; >>sphera.asy echo usepackage("animate"); >>sphera.asy echo settings.tex="pdflatex"; >>sphera.asy echo import izgraphiki; >>sphera.asy echo animation a; >>sphera.asy echo int n=%n%; >>sphera.asy echo for(int i=0; i ^<= n; ++i) { >>sphera.asy echo a.add(); >>sphera.asy echo restore(); >>sphera.asy echo } >>sphera.asy echo erase(); >>sphera.asy echo label(a.pdf(BBox(0.25cm),delay=250,"controls,loop,autoplay",multipage=false)); >>sphera.asy for /l %%k in (0,1,%n%) do ( echo settings.twice=true; >> sphera+%%k.asy echo usepackage("animate"^); >> sphera+%%k.asy echo import solids; >> sphera+%%k.asy echo settings.tex="pdflatex"; >> sphera+%%k.asy echo import animation; >> sphera+%%k.asy echo settings.outformat="pdf"; >> sphera+%%k.asy echo settings.axes3=true; >> sphera+%%k.asy echo import graph3; >> sphera+%%k.asy echo import palette; >> sphera+%%k.asy echo currentprojection=orthographic(1,1,1^); >> sphera+%%k.asy echo limits((-1.3,-1.3,-1.3^),(1.3,1.3,1.3^)^); >> sphera+%%k.asy echo unitsize(6cm^); >> sphera+%%k.asy echo animation a=animation(global=false^); //  (global=false^)   >>sphera+%%k.asy echo //C:\Program Files\Asymptote/plain_shipout.asy: 87.10: runtime: Cannot rename _sphera+2+0_.pdf to >>sphera+%%k.asy echo //_sphera+2+0.pdf >>sphera+%%k.asy echo for(int i=0; i ^<= 0; ++i^) { >>sphera+%%k.asy echo real f(real x^) {return sqrt(1-x^^2^);} >> sphera+%%k.asy echo pair F(real x^) {return (x,f(x^)^);} >> sphera+%%k.asy echo triple F3(real x^) {return (x,f(x^),0^);} >> sphera+%%k.asy echo path p=graph(F,-1+i,-1+i+%%k/%n%^); >> sphera+%%k.asy echo path3 p3=path3(p^); >> sphera+%%k.asy echo revolution b=revolution(p3,X,0,360^); >> sphera+%%k.asy echo draw(surface(b^),green^); >> sphera+%%k.asy echo real g(real x^) {return sqrt(1-x^^2^);} >> sphera+%%k.asy echo pair G(real x^) {return (x,f(x^)^);} >> sphera+%%k.asy echo triple G3(real x^) {return (x,g(x^),0^);} >> sphera+%%k.asy echo path q=graph(G,1-i-%%k/%n%,1-i^); >> sphera+%%k.asy echo path3 q3=path3(q^); >> sphera+%%k.asy echo revolution c=revolution(q3,X,0,360^); >> sphera+%%k.asy echo draw(surface(c^),red^); >> sphera+%%k.asy echo axes3("$x$","$y$","$z$",Arrow3^); >> sphera+%%k.asy echo a.add(^); >>sphera+%%k.asy echo restore(^); >>sphera+%%k.asy echo } >>sphera+%%k.asy echo erase(^); >>sphera+%%k.asy echo label(a.pdf(^)^); >>sphera+%%k.asy ) rem for /f %%l in (0,1,%n%) do asy '_sphera+%%l'.asy for /l %%l in (0,1,%n%) do ( asy sphera+%%l.asy taskkill /F /IM AcroRd32.exe ) for /l %%l in (0,1,%n%) do rename sphera+%%l+0.pdf _sphera+%%l.pdf asy sphera.asy
      
      





Please pay attention to the line



 echo for(int i=0; i ^<= n; ++i) { >>sphera.asy
      
      





since the symbol <



has a special meaning for the command line interpreter, in order for this interpreter to take this symbol in literal meaning, I escaped this symbol by putting the ^



symbol in front of it. ^



, . , , ,



 for /l %%k in (0,1,%n%) do (
      
      





, , . ( , , sphera.asy :



 settings.twice=true; usepackage("animate"); settings.tex="pdflatex"; import izgraphiki; animation a; int n=44; for(int i=0; i <= n; ++i) { a.add(); restore(); } erase(); label(a.pdf(BBox(0.25cm),delay=250,"controls,loop,autoplay",multipage=false));
      
      





sphera+0.asy, sphera+1.asy,..., sphera+44.asy, Asymptote 2d- sphera+0.pdf, sphera+1.pdf,..., sphera+44.pdf. , sphera+4.asy :



 settings.twice=true; usepackage("animate"); import solids; settings.tex="pdflatex"; import animation; settings.outformat="pdf"; settings.axes3=true; import graph3; import palette; currentprojection=orthographic(1,1,1); limits((-1.3,-1.3,-1.3),(1.3,1.3,1.3)); unitsize(6cm); animation a=animation(global=false); //          (global                  //C:\Program Files\Asymptote/plain_shipout.asy: 87.10: runtime: Cannot rename _sphera+2+0_.pdf to //_sphera+2+0.pdf for(int i=0; i <= 0; ++i) { real f(real x) {return sqrt(1-x^2);} pair F(real x) {return (x,f(x));} triple F3(real x) {return (x,f(x),0);} path p=graph(F,-1+i,-1+i+4/44); path3 p3=path3(p); revolution b=revolution(p3,X,0,360); draw(surface(b),green); real g(real x) {return sqrt(1-x^2);} pair G(real x) {return (x,f(x));} triple G3(real x) {return (x,g(x),0);} path q=graph(G,1-i-4/44,1-i); path3 q3=path3(q); revolution c=revolution(q3,X,0,360); draw(surface(c),red); axes3("$x$","$y$","$z$",Arrow3); a.add(); restore(); } erase(); label(a.pdf());
      
      





, sphera+4.asy TeXworks', UTF-8:



image



ANSI. , - .asy, , , Asymptote. 2d- . 2d-, , , 2d-. - .asy , . 2d- sphera+0+0.pdf, sphera+1+0.pdf,..., sphera+44+0.pdf _sphera+0.pdf, _sphera+1.pdf,..., _sphera+44.pdf, , , Asymptote sphera.asy. . .gif , .gif - . .gif, .pdf , , , , . ., , .pdf , .gif . .gif , :



 cd /d %0\.. echo off set n=44 echo import graph; >sphera.asy echo settings.twice=true; >>sphera.asy echo usepackage("animate"); >>sphera.asy echo settings.tex="pdflatex"; >>sphera.asy echo import izgraphikigif; >>sphera.asy echo animation a; >>sphera.asy echo yequals(Label("$y=-1$",1.0),-1,extend=true,linetype("4 4")); >>sphera.asy echo int n=%n%; >>sphera.asy echo for(int i=0; i ^<= n; ++i) { >>sphera.asy echo a.add(); >>sphera.asy echo restore(); >>sphera.asy echo } >>sphera.asy echo erase(); >>sphera.asy echo a.movie(); >>sphera.asy for /l %%k in (0,1,%n%) do ( echo settings.twice=true; > sphera+%%k.asy echo usepackage("animate"^); >> sphera+%%k.asy echo import solids; >> sphera+%%k.asy echo settings.tex="pdflatex"; >> sphera+%%k.asy echo import animation; >> sphera+%%k.asy echo settings.outformat="pdf"; >> sphera+%%k.asy echo settings.axes3=true; >> sphera+%%k.asy echo import graph3; >> sphera+%%k.asy echo import palette; >> sphera+%%k.asy echo currentprojection=orthographic(1,1,1^); >> sphera+%%k.asy echo limits((-1.3,-1.3,-1.3^),(1.3,1.3,1.3^)^); >> sphera+%%k.asy echo unitsize(6cm^); >> sphera+%%k.asy echo animation a=animation(global=false^); //  (global=false^)   >>sphera+%%k.asy echo //C:\Program Files\Asymptote/plain_shipout.asy: 87.10: runtime: Cannot rename _sphera+2+0_.pdf to >>sphera+%%k.asy echo //_sphera+2+0.pdf >>sphera+%%k.asy echo for(int i=0; i ^<= 0; ++i^) { >>sphera+%%k.asy echo real f(real x^) {return sqrt(1-x^^2^);} >> sphera+%%k.asy echo pair F(real x^) {return (x,f(x^)^);} >> sphera+%%k.asy echo triple F3(real x^) {return (x,f(x^),0^);} >> sphera+%%k.asy echo path p=graph(F,-1+i,-1+i+%%k/%n%^); >> sphera+%%k.asy echo path3 p3=path3(p^); >> sphera+%%k.asy echo revolution b=revolution(p3,X,0,360^); >> sphera+%%k.asy echo draw(surface(b^),green^); >> sphera+%%k.asy echo real g(real x^) {return sqrt(1-x^^2^);} >> sphera+%%k.asy echo pair G(real x^) {return (x,f(x^)^);} >> sphera+%%k.asy echo triple G3(real x^) {return (x,g(x^),0^);} >> sphera+%%k.asy echo path q=graph(G,1-i-%%k/%n%,1-i^); >> sphera+%%k.asy echo path3 q3=path3(q^); >> sphera+%%k.asy echo revolution c=revolution(q3,X,0,360^); >> sphera+%%k.asy echo draw(surface(c^),red^); >> sphera+%%k.asy echo axes3("$x$","$y$","$z$",Arrow3^); >> sphera+%%k.asy echo a.add(^); >>sphera+%%k.asy echo restore(^); >>sphera+%%k.asy echo } >>sphera+%%k.asy echo erase(^); >>sphera+%%k.asy echo label(a.pdf(^)^); >>sphera+%%k.asy ) for /l %%l in (0,1,%n%) do ( asy sphera+%%l.asy taskkill /F /IM AcroRd32.exe ) rem for /l %%l in (0,1,%n%) do rename sphera+%%l+0.pdf _sphera+%%l.pdf asy sphera.asy
      
      





, , .gif wheel.asy. ,



 yequals(Label("$y=-1$",1.0),-1,extend=true,linetype("4 4"));
      
      





sphera.asy , . , /« » .asy . .gif, Imagemagick 2d-:



image



, . , . ?



magick *.eps sphere.gif



, , 2d- .eps. .gif . , 10 )). , , . , , , animation.asy. , ( ) ? .gif . , izgraphiki.asy – animation.asy – .pdf ( (. ) 3d ) .gif ( (. ) 3d ). , «» . «» .pdf, animation.asy, ( , ) - 4 , , -, : : , . , ( ) . animation.asy:



 string format=nativeformat(); plain.shipout(name,f,format=format,view=false); files.push(name+"."+format); shipped=false;
      
      





, izgraphiki.asy:



 //string format=nativeformat(); //plain.shipout(name,f,format=format,view=false); //files.push(name+"."+format); //shipped=false;
      
      





izgraphiki.asy:



izgraphiki.asy
 /***** * animation.asy * Andy Hammerlindl and John Bowman 2005/11/06 * * Produce GIF, inline PDF, or other animations. *****/ // animation delay is in milliseconds real animationdelay=50; typedef frame enclosure(frame); frame NoBox(frame f) { return f; } enclosure BBox(real xmargin=0, real ymargin=xmargin, pen p=currentpen, filltype filltype=NoFill) { return new frame(frame f) { box(f,xmargin,ymargin,p,filltype,above=false); return f; }; } struct animation { picture[] pictures; string[] files; int index; string prefix; bool global; // If true, use a global scaling for all frames; this requires // extra memory since the actual shipout is deferred until all frames have // been generated. void operator init(string prefix="", bool global=true) { prefix=replace(stripdirectory(outprefix(prefix))," ","_"); this.prefix=prefix; this.global=global; } string basename(string prefix=stripextension(prefix)) { return "_"+prefix; } string name(string prefix, int index) { return stripextension(prefix)+"+"+string(index); } private string nextname() { string name=basename(name(prefix,index)); ++index; return name; } void shipout(string name=nextname(), frame f) { // string format=nativeformat(); // plain.shipout(name,f,format="png",view=false); //generiruet!!!! //files.push(name+"."+format); // shipped=false; } void add(picture pic=currentpicture, enclosure enclosure=NoBox) { if(global) { ++index; pictures.push(pic.copy()); } else this.shipout(enclosure(pic.fit())); } void purge(bool keep=settings.keep) { if(!keep) { for(int i=0; i < files.length; ++i) delete(files[i]); } } int merge(int loops=0, real delay=animationdelay, string format="gif", string options="", bool keep=settings.keep) { string args="-loop " +(string) loops+" -delay "+(string)(delay/10)+ " -alpha Off -dispose Background "+options; for(int i=0; i < files.length; ++i) args += " " +files[i]; int rc=convert(args,prefix+"."+format,format=format); this.purge(keep); if(rc == 0) animate(file=prefix+"."+format,format=format); else abort("merge failed"); return rc; } void glmovie(string prefix=prefix, projection P=currentprojection) { if(!view() || settings.render == 0) return; fit(prefix,pictures,view=true,P); } // Export all frames with the same scaling. void export(string prefix=prefix, enclosure enclosure=NoBox, bool multipage=false, bool view=false, projection P=currentprojection) { if(pictures.length == 0) return; if(!global) multipage=false; bool inlinetex=settings.inlinetex; if(multipage) settings.inlinetex=false; frame multi; frame[] fits=fit(prefix,pictures,view=false,P); for(int i=0; i < fits.length; ++i) { string s=name(prefix,i); if(multipage) { add(multi,enclosure(fits[i])); newpage(multi); files.push(s+"."+nativeformat()); } else { if(pictures[i].empty3() || settings.render <= 0) this.shipout(s,enclosure(fits[i])); else // 3D frames files.push(s+"."+nativeformat()); } } if(multipage) { plain.shipout(prefix,multi,view=view); settings.inlinetex=inlinetex; } shipped=true; } string load(int frames, real delay=animationdelay, string options="", bool multipage=false) { if(!global) multipage=false; string s="\animategraphics["+options+"]{"+format("%.18f",1000/delay,"C")+ "}{"+basename(); if(!multipage) s += "+"; s += "}{0}{"+string(frames-1)+"}"; return s; } bool pdflatex() { return latex() && pdf(); } string pdf(enclosure enclosure=NoBox, real delay=animationdelay, string options="", bool keep=settings.keep, bool multipage=true) { if(settings.inlinetex) multipage=true; if(!global) multipage=false; if(!pdflatex()) abort("inline pdf animations require -tex pdflatex or -tex xelatex"); if(settings.outformat != "") settings.outformat="pdf"; string filename=basename(); string pdfname=filename+".pdf"; if(global) export(filename,enclosure,multipage=multipage); shipped=false; if(!keep) { exitfcn currentexitfunction=atexit(); void exitfunction() { if(currentexitfunction != null) currentexitfunction(); if(multipage || !settings.inlinetex) this.purge(); if(multipage && !settings.inlinetex) delete(pdfname); } atexit(exitfunction); } if(!multipage) delete(pdfname); return load(index,delay,options,multipage); } int movie(enclosure enclosure=NoBox, int loops=0, real delay=animationdelay, string format=settings.outformat == "" ? "gif" : settings.outformat, string options="", bool keep=settings.keep) { if(global) { if(format == "pdf") { export(enclosure,multipage=true,view=true); return 0; } export(enclosure); } return merge(loops,delay,format,options,keep); } } animation operator init() { animation a=animation(); return a; }
      
      







,



 plain.shipout(name,f,format="png",view=false); //generiruet!!!!
      
      





- animation.asy, , : , . .gif , izgraphiki.asy, izgraphikigif.asy animation.asy —
 plain.shipout(name,f,format= format,view=false);
      
      





, . . izgraphikigif.asy :



 //plain.shipout(name,f,format= format,view=false);
      
      





, . , animation.asy

izgraphikigif.asy , . , izgraphikigif.asy .pdf , 2 . , , - if, , : , , Asymptote. , , , , , , – :



 cd /d %0\.. echo off set n=2 set name=kriv echo settings.twice=true; >%name%.asy echo settings.prc=false; >> %name%.asy echo // Uncomment the following 2 lines to support pdf animations: >>%name%.asy echo usepackage("animate"^); >>%name%.asy echo settings.tex="pdflatex"; >>%name%.asy echo import sinoid; >>%name%.asy echo animation a; >>%name%.asy echo int n=%n%; >>%name%.asy echo for(int i=0; i ^<= n; ++i^) { >>%name%.asy echo a.add(^); // Add currentpicture to animation. >>%name%.asy echo restore(^); >>%name%.asy echo } >>%name%.asy echo erase(^); >>%name%.asy echo label(a.pdf(BBox(0.25cm^),delay=250,"controls",multipage=false^)^); >>%name%.asy for /l %%k in (0,1,%n%) do ( echo import graph; > %name%+%%k.asy echo settings.twice=true; >> %name%+%%k.asy echo usepackage("animate"^); >> %name%+%%k.asy echo settings.tex="pdflatex"; >> %name%+%%k.asy echo import animation; >> %name%+%%k.asy echo limits((-6.3,-6.3^),(6.3,6.3^)^); >> %name%+%%k.asy echo size(0,100^); >> %name%+%%k.asy echo animation a=animation(global=false^);>>%name%+%%k.asy echo for(int i=0; i ^<= 0; ++i^) { >>%name%+%%k.asy echo real r=0.925; >> %name%+%%k.asy echo real R=3.61; >> %name%+%%k.asy echo real d=1.39; >> %name%+%%k.asy echo real x(real t^) {return (R+r^)*cos(t^)-d*cos((R+r^)*t/r^);} >> %name%+%%k.asy echo real y(real t^) {return (R+r^)*sin(t^)-d*sin((R+r^)*t/r^);} >> %name%+%%k.asy echo draw(graph(x,y,0,2*pi*%%k/%n%^),green^); >> %name%+%%k.asy echo axes("$x$","$y$",Arrow^); >> %name%+%%k.asy echo a.add(^); // Add currentpicture to animation. >>%name%+%%k.asy echo restore(^); >>%name%+%%k.asy echo } >>%name%+%%k.asy echo erase(^); >>%name%+%%k.asy echo // Merge the images into a pdf animation. >>%name%+%%k.asy echo label(a.pdf(^)^); >>%name%+%%k.asy ) rem for /f %%l in (0,1,%n%) do asy '%name%+%%l'.asy rem asy *.asy for /l %%l in (0,1,%n%) do ( asy %name%+%%l.asy taskkill /IM AcroRd32.exe ) for /l %%l in (0,1,%n%) do rename %name%+%%l.pdf _%name%+%%l.pdf asy %name%.asy
      
      







. , , : kriv.asy , 2d-.pdf , , , kriv.asy Asymptote , kriv.pdf , , , .pdf, .asy : , , . , : play , , , , ! – . , , , : kriv epicykloida. , Astroida. name krivaja, – kriv .pdf . , Asymptote: , , Astroida.asy, . .mpg (, ) , , , , - . , , , Asymptote : .asy, .pdf .asy, .gif, -, , .



.asy, .pdf, :



 label(a.pdf());
      
      





.asy, .gif, :



 a.movie();
      
      





.asy, .mpg, , .asy, .gif. .mpg .asy,



 settings.twice=true;
      
      





, , .



All Articles