// Persistence of Vision Ray Tracer Scene Description File
// File: ?.pov
// Vers: 3.6
// Desc: Basic Scene Example
// Date: mm/dd/yy
// Auth: ?
//

#version 3.6;

#include "colors.inc"
#include "mrg_misc3.inc"
global_settings {
  assumed_gamma 1.0
}

// ----------------------------------------
#declare lclock=clock+0;


#declare rescale=1;
// create a regular point light source 
#declare ls_dd=.2;
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate 0
}
/*
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate ls_dd*y
}
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate -ls_dd*y
}
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate ls_dd*x
}
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate -ls_dd*x
}
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate ls_dd*z
}
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate -ls_dd*z
}
*/
sphere {
  0.0, rescale
  #declare scolor=<1,.7,.5>;
  texture {
    pigment {
      spotted   
      turbulence 8
      color_map {
        [0.00 color rgb scolor ]
        [0.80 color rgb scolor ]
        [0.95 color rgb scolor*0 ]
        
        [1.00 color rgb scolor*0 ]
      }
      scale 1.1
    }
    finish{
      specular 0.6 ambient 1.2
    }
  }     scale 1/rescale
  no_shadow 
}

sphere 
 { 0,1 pigment { rgbt 1 } hollow
   interior
   { media
     { emission 1
       density
       { spherical density_map
         { [0 rgb 0]
           [0.4 rgb <1,0,0>]
           [0.8 rgb <1,1,0>]
           [1 rgb 1]
         }
       }
     }
  }
 scale 1.2
 }
       
       
#declare ring_radius = 20;
#declare ring_height =.2;
#declare ring_thickness=.05;
#declare ringwall_thickness=.025;
#declare ringwall_height=.05;

#difference{
     cylinder{-ring_height*y,ring_height*y,ring_radius+ring_thickness}
     union{
          cylinder{-(ring_height-ringwall_thickness)*y,(ring_height-ringwall_thickness)*y,ring_radius+.2*ring_thickness} //cut "groove"
     
          cylinder{-1.2*ring_height*y,1.2*ring_height*y,ring_radius-ringwall_height}  //cut center to top of walls
     }     
     pigment{color Gray}
}       
/**/
//atmosphere
#difference{
     cylinder{-(ring_height-ringwall_thickness)*y,(ring_height-ringwall_thickness)*y,ring_radius+.2*ring_thickness}   
     cylinder{-1.2*ring_height*y,1.2*ring_height*y,ring_radius-ringwall_height}  //cut center to top of walls
     pigment { rgbt 1 } 
     hollow
     interior { 
          media { 
               scattering { 4, <0.5,.5,.7> }
          }
     }
} 
      
//surface
#difference{
     cylinder{-(ring_height-ringwall_thickness)*y,(ring_height-ringwall_thickness)*y,ring_radius+.2*ring_thickness}
     cylinder{-1.2*ring_height*y,1.2*ring_height*y,ring_radius}  
     texture{
         pigment {
           spotted   
           turbulence 2
           color_map {
             [0.00 color Blue*.025 ]
             [0.30 color Blue*.5 ]
             [0.550 color <.00,.05,.00> ]
             [.85 color Brown*.25 ]
             [1.00 color Brown ]
           }
         }
         normal {
           spotted
           turbulence 2
           lambda 2
           normal_map {
             [0.4 dents .15 scale .01]
             [0.55 agate turbulence 1 scale 5]
             [0.85 agate turbulence 2 scale 10]
           }
         }
     }
     rotate -y*lclock*10
}       


       
//shutters 

#declare shutter_radius=ring_radius-20*ring_thickness;
#declare shutter_height=ring_height*1.75;
#declare n_shutters = 12;
#declare shutter_dx= .6*2*pi*shutter_radius/(4*n_shutters);
#declare cable_thickness= .2*ring_thickness;
#declare shutter_dz=cable_thickness/4;
#declare i=0;
#while(i<n_shutters)
     box{-<shutter_dx,shutter_height,shutter_dz>,<shutter_dx,shutter_height,shutter_dz>
          pigment{color Gray*.2}
          translate -z*shutter_radius
          rotate i/n_shutters*360*y -y*lclock*5
     }

     #declare i=i+1;
#end     




 
torus{shutter_radius, cable_thickness
     pigment{color Gray*.2}
     translate shutter_height*y
}  


torus{shutter_radius, cable_thickness
     pigment{color Gray*.2}
     translate -shutter_height*y
}  

//durations
#declare dt1=10;
#declare dt2=20;
#declare dt3=10;
#declare dtz1=1;
#declare dtz2=.5;
//starts
#declare t1=0;
#declare t2=dt1;
#declare t3=t2+dt2;
#declare tz1=dt1-dtz1;
#declare tz2=t3;

//camera motion
#declare dq2=360;
#declare rf=.99*ring_radius;
#declare vloop=2*pi*dq2/360*rf/dt2;
#declare dx=12*rf;
#declare v0=2*dx/dt1-vloop;
#declare aa=(vloop-v0)/dt1;
#declare y0=8;
#declare qq=function(tt) { dq2/dt2*max(min(tt-t2,t3),0) }                
#declare yy=function(tt) { y0*(1- trans(tt/dt1)+1.25*trans((tt-t3)/dt3) )}                
#declare zz=function(tt) { -rf*cos(radians(qq(tt))) +.2*rf*( 1-trans((tt-tz1)/dtz1)+1.5*trans((tt-t3)/dtz2) )   }                
#declare xx=function(tt) { rf*sin(radians(qq(tt))) +(-dx+v0*min(tt,t2)+.5*aa*min(tt,t2)*min(tt,t2) ) +vloop*max(tt-t3,0)-.5*aa*max(tt-t3,0)*max(tt-t3,0)  }                



/*  

//test path
union{
     #declare tn=0;
     #declare rnew=<xx(0), yy(0),zz(0)>;
     #while(tn<20)
          #declare tn=tn+.025;
          #declare rold=rnew;
          #declare rnew=<xx(tn), yy(tn),zz(tn)>;
          cylinder{rold,rnew,1*cable_thickness pigment{color Yellow} no_shadow no_reflection}
     
     #end
     translate -y*2*cable_thickness
}

*/
    

//camera position
#declare dt=1e-4;
#declare cpos =<xx(lclock), yy(lclock),zz(lclock)>;
#declare vv=<xx(lclock+dt), yy(lclock+dt),zz(lclock+dt)>-cpos;
#declare vn=vv/vlength(vv);
//camera orientation
#declare dtr=2.5;
#declare tr1=t2-1;
#declare tr2=t3-dtr;
#declare dtl = 1.5;
#declare tl1 = t2-3*dtl; //look forward
#declare tl2 =t2+.5*dt2;  //look back center
#declare tl3 = t2+.75*dt2; //look forward
#declare tl4 =t3-dtl;  //look back center
#declare skyv=vrotate(y, vn*89*( trans((lclock-tr1)/dtr) - trans((lclock-tr2)/dtr) ) );
#declare lookie_there=0 +(cpos+vn*rf)*( trans( (lclock-tl1)/dtl ) - trans( (lclock-tl4)/dtl )  )
                        +(skyv-.90*vn)*rf*( trans( (lclock-tl2)/dtl ) - trans( (lclock-tl3)/dtl )  ) ;

// #declare cpos= <.99*ring_radius, 0, -0>;
// #declare cpos=(-1.2*rf*z +.2*rf*y)*2;

camera {
  //location  <0.0, 8.0, -14.0>*1
  location  cpos
  //direction vn
  sky       skyv
  look_at   lookie_there  
  right     x*image_width/image_height
}





#declare cel_sphr_rad=40000;
#declare stars=union{
     #declare ra=0;
     #declare dec=0;
     #declare mag=0;
     #declare con="aaa";
     #fopen MyFile "decimal_yale.csv" read
     #read (MyFile,ra,dec,mag,con)
     #while (mag<=6)
          sphere { <0, 0, -cel_sphr_rad>, 0.0025*(1-mag/14)*cel_sphr_rad
               texture{
                    pigment{color rgb 1*(1-mag/6)}
                    finish{ambient 2 diffuse 0}
               }
               rotate x*dec //rotate -z towards y for "altitude" like declination
               rotate -y*ra //right ascension in a left handed coord system...
                
          }   
          #read (MyFile,ra,dec,mag,con)
     
     #end
     #fclose MyFile



};
object { stars}               
