Fly through animation using POVRAY of 3 cover of torus.

-Animation by Timothy Jones


torus.c:
#include < stdlib.h>
#include < math.h>
#include < fstream.h>
#include < iostream.h>
#include < cstdio>

//Adaptation by TJ of a Bob Gilmore program
//written in f

int main(int argc, char *argv[]){
  int fiii= atoi(argv[1]);
  float iii=1.0*fiii/10;
  printf("%i \n",fiii);
  int i,nn,m,ord,j;
  nn=75000;
  double pi,r1,r2;
  double phi,alpha,beta,theta;
  double u,v,z,r,x,y,angle,oldang;
  double uu,zz,aa,bb;
  double orig [nn][3];
  double u0,v0,eps1,eps2,rr,renorm [nn][3];
  double delu,delv,rat;

  ///////////////////////////////////PART ONE//////////////

  pi = 3.1415926535;
  alpha = 1.0/12.52;//  !!! 1.0/25.1
  aa = 0.45;   //!!!  0.85
  bb = sqrt(1.0-aa*aa);
  r1 = 1.0;

  FILE * fp;
  fp  = fopen ("donut.dat","w");
  for(i=1; i<=nn;i++){    //    !!!  nn/1000= numbor of wraps in long. dir.
    theta = i*(2*pi)/1000.0;    
    phi   = alpha*theta;  //   !!! quasiperiodic ratio
    r2 = 2.0 + r1*cos(phi); //  !!! distinace from origin
    uu  = r2*cos(theta);  //     !!! (uu,v,zz) coordinates
    v   = r2*sin(theta);  //
    zz  = r1*sin(phi);  
    u = aa*uu - bb*zz;  //   !!!   rotation in (uu,zz) plane
    z = bb*uu + aa*zz;  
    orig[i][1]=u; //    !!!   output coordinate triple
    orig[i][2]=v;
    orig[i][3]=z; 
    fprintf(fp, "SP(%f, %f, %f, 0.05)\n",u/2,v/2,z/2 + 10);}

  fclose(fp);

  /////////////////////////////////////END P.1////////////////

  /////////////////////////////////////Momma loop/////////////
 

  //  u0 =-1.8;    //!!!  coordinates of roation axis
  // v0 = 0.0;


  //for(iii=0; iii<=100; i++){
  // originally iii*0.01 --> 0.0001 so that it goes from 0-10 effectively
  u0 = -3.0 + (iii*0.01)*(4+3);
  v0 = 0.0;
  
  //cylinder {<-3,0,7+(clock/1000)*7>,<3,0,7+(clock/1000)*7>,.1 texture{pigment{color Red} finish {ambient 0.15 diffuse 0.75 reflection 0.1 phong 
1}}}

  /////////////////////////////////////PART 2/////////////////
  eps1=0.001;
  eps2=0.01;

  for(i=1;i<=nn;i++){
    renorm[i][3]=orig[i][3];
    delu = orig[i][1]-u0;
    delv = orig[i][2]-v0;
    rr   = sqrt(delu*delu+delv*delv);

    if(rr>eps2){
      renorm[i][1]=orig[i][1];
      renorm[i][2]=orig[i][2];}

    if(rreps1)&&(rr 1.3)){m=m+1;}
    if((angle > 1.3) && (oldang < -1.3)){m=m-1;}
    oldang = angle;
    angle = angle+m*pi;
    x = pow(r,(1/(1.0*ord)))*cos(angle/ord);
    y = pow(r,(1/(1.0*ord)))*sin(angle/ord);
    fprintf(fp2,"SP(%f, %f, %f, 0.05)\n",x,y,z);
    //    write(13,'(3f12.6)')x,y,z
    }

    //For the cylinder
    fprintf(fp2,"cylinder {<-3,0,%f>,<3,0,%f>,.1 texture{pigment{color Red} finish {ambient 0.15 diffuse 0.75 reflection 0.1 phong 
1}}}\n",10+u0/2,10+u0/2);
    fclose(fp2);

/// cylinder {<-3,0,7+(clock/1000)*7>,<3,0,7+(clock/1000)*7>,.1 texture{pigment{color Red} finish {ambient 0.15 diffuse 0.75 reflection 0.1 phong 
1}}}
    /////////////////////////////////////END 3/////
    //     }
  ///END MAMMA

}

temp.pov:
#include "colors.inc"  
#include "textures.inc"
// camera-----------------------------------------------------------
#declare Cam1 =camera {location  <2-(clock)/10 , (clock-10.0)/2-5 ,clock-20>
                       look_at   <0.2 , 1.0 , 0.0>}
camera{Cam1}                                                 //<---1   
// sun -------------------------------------------------------------
light_source{<1500,2000,-2500> color White*0.7}
light_source{<-100, 100,-200> color Yellow*0.7}
background {
   color rgb <0,0,0>
}

#macro SP(x0,y0,z0,r0)
    sphere {   , r0
               pigment { rgb <1,1,1> }
               finish { reflection .5 phong .7 }} 
#end

500.ini:
Output_File_Type=N
Width=500
Height=500
Quality=9
Antialias=on
Antialias_Threshold=0.001
Initial_Frame=1
Final_Frame=700
Initial_Clock=0
Final_Clock=40

Linux command line:
#> g++ -o torus torus.c
#> ./torus 500
#> cat temp.pov > 500.pov
#> cat 500 >> 500.pov
#> povray 500.ini 500.pov Display=False
May need -Display instead of Display