"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/examples/animations/cube.asy" (18 Nov 2019, 946 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import math;
    2 import bsp;
    3 import animation;
    4 
    5 size(100,100);
    6 
    7 animation a;
    8 
    9 void face(face[] faces, path3 p, int j, int k) {
   10   picture pic=faces.push(p);
   11   filldraw(pic,project(p),Pen(j));
   12   int sign=(k % 2 == 0) ? 1 : -1;
   13   transform t=scale(4)*transform(dir(p,0,sign),dir(p,0,-sign));
   14   label(pic,t*(string) j,project(0.5*(min(p)+max(p))));
   15 }
   16 
   17 void snapshot(transform3 t)
   18 {
   19   static transform3 s=shift(-0.5*(X+Y+Z));
   20   save();
   21   
   22   face[] faces;
   23   int j=-1;
   24   transform3 T=t*s;
   25   for(int k=0; k < 2; ++k) {
   26     face(faces,T*plane((1,0,0),(0,1,0),(0,0,k)),++j,k);
   27     face(faces,T*plane((0,1,0),(0,0,1),(k,0,0)),++j,k);
   28     face(faces,T*plane((0,0,1),(1,0,0),(0,k,0)),++j,k); 
   29   }
   30   add(faces);
   31   
   32   a.add();
   33   restore();
   34 }
   35 
   36 int n=50;
   37 
   38 real step=360/n;
   39 for(int i=0; i < n; ++i)
   40   snapshot(rotate(i*step,X));
   41 for(int i=0; i < n; ++i)
   42   snapshot(rotate(i*step,Y));
   43 for(int i=0; i < n; ++i)
   44   snapshot(rotate(i*step,Z));
   45 
   46 a.movie(loops=10,delay=50);