/*
; Persistence Of Vision raytracer version 3.5 sample file.

Antialias=on

Antialias_Threshold=0.3
Antialias_Depth=3
Input_File_Name=x_ray_photodisintegration.pov
Output_File_Name=x_ray_photodisintegration

Initial_Frame=1
Final_Frame=180
Initial_Clock=0
Final_Clock=9

Cyclic_Animation=off
Pause_when_Done=off
*/
#version 3.5;

#include "colors.inc"
#include "rand.inc"

global_settings {
  assumed_gamma 1.0
    ambient_light rgb <1,1,1> 
    max_trace_level 7
}
#declare ltrans=function(tt) { max(min(tt,1),0) }                 //linear transition 

// ----------------------------------------
// create a regular point light source
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate <-20, 40, -20>
}

camera {
  location  10*<0.0, 0,-6.50>
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <0.0, 0.0,  0.0>
}
#declare lclock=clock+0;   


#declare linterpolater=function(xx,xa,xb,a,b){
        (xx-xa)*(b-a)/(xb-xa)+a
}
// vetices of tetrahedron
#declare p1=vrotate(< 0, sqrt(3) - 1/sqrt(3),  0>,z*30);
#declare p2=vrotate(<-1, - 1/sqrt(3),  0>,z*30);
#declare p3=vrotate(< 1, - 1/sqrt(3),  0>,z*30);
#declare p4=vrotate(< 0,   0, 2 * sqrt(2/3)> ,z*30); 
#declare qp2=120;
#declare p1=vrotate(p1,y*qp2);
#declare p2=vrotate(p2,y*qp2);
#declare p3=vrotate(p3,y*qp2);
#declare p4=vrotate(p4,y*qp2);
 
 
 //He4
 
 
//building an approximate nucleus from a simple cubic array of nucleons  2, 8, 18, 8
#declare n_size=.8;     //"size" of nucleons ->sets scale in image
#declare proton=sphere{0, n_size*1 texture {pigment { color rgb <.9,.0,.0> } finish{ambient .40 diffuse .50}}};
#declare neutron=sphere{0, n_size*1 texture {pigment { color rgb <.2,.2,.2> } finish{ambient .40 diffuse .50}}};
#declare n_disp= .8*n_size;




#declare e_size = n_size*.75;
#declare electron=sphere{0, e_size texture {pigment { color rgbt <.2,.2,.9,0> } finish{ambient .80 diffuse .50}}};
#declare enorb = 8*n_size;
//photon

#declare photon_wave=function(x) {
        (cos(5*x) )*
    exp(-.09*abs((x+3.5)*(x+3.5)))
        }
#declare wstart=-2.5*pi;
#declare wend =0;
#declare wthick=.15;
#declare wnseg=50;
#declare wxnew=wstart;
#declare wynew=photon_wave(wxnew);
#declare wdx=(wend-wstart)/wnseg;
 
#declare phsize=1*n_size;
//photon location
#declare x_0=-5*enorb;
#declare c=abs(x_0)/2;//2sec in, need more for e out sec out
#declare xp=x_0+c*lclock;
#declare Qe=20;
#object {proton translate p1*n_disp+ max(0,lclock-2.2)*c*<.32,.16,0>}      //top slot
#object {neutron translate p2*n_disp+ max(0,lclock-2.2)*c*<-.1,.34,0>}     // bottom slot
#object {proton translate p3*n_disp+ max(0,lclock-2.2)*c*<-.3,-.19,0>}        //back slot
#object {neutron translate p4*n_disp+ max(0,lclock-2.2)*c*<.6,-.32,0>}    //front slot

#declare pcount=0;
#declare photon=union{
     sphere_sweep {
       cubic_spline
       wnseg+1,
                #while (pcount<wnseg+1)
                        #declare wxnew=pcount*wdx+wstart;
                        #declare wynew=photon_wave(wxnew);
                        <wxnew,wynew,0>,wthick
                        #declare pcount=pcount+1;
                #end
     }
                cone{(wxnew-1*wdx)*x,4*wthick,(wxnew+1.15)*x,0 scale <1,1,wthick>}
                           
                scale phsize*<1,1,1>
                translate xp*x 
} 
#if(lclock<=2.4)

intersection{
     object{photon   }
     cylinder {0,-15*enorb*x,phsize*1.2}        
                texture {pigment { color rgbt <1,1,0,0> } finish{ambient 1 diffuse 1}}
       translate  -z
}

#end

 object{ electron translate enorb*y +.2*c*y*max(0,lclock-2.5)}
 object{ electron translate -enorb*y -.2*c*y*max(0,lclock-2.5)}

#if(lclock<2.5)

     #declare ncloud=3*n_size;
     sphere{ 0,ncloud
         texture {pigment {color rgbf <1,1,1,1>}}
         hollow
         interior {
             media {
                 emission color rgbt <.3*(1-ltrans((lclock-2))/.5),.0,.0,1>
                 scattering {5}
                 intervals 2 samples 32
                 method 3
                // aa_threshold 0.3 aa_level 5
                 density {spherical scale ncloud}
             }
         }
     }
#end     
#if(lclock<2.7)
     torus{enorb,e_size/3
              texture {pigment { color rgbt <.2,.2,.9,.5+.5*ltrans((lclock-2.2)/.5)> } finish{ambient .40 diffuse .50}}
              rotate x*90}
     
     sphere{ 0,1.5*enorb
         texture {pigment {color rgbf <1,1,1,1>}}
         hollow
         interior {
             media {
                 emission color rgb <.0,.0,.03*(1-ltrans((lclock-2.2)/.5))>
                 scattering {2}
                 intervals 3 samples 32
                 method 3
                // aa_threshold 0.3 aa_level 5
                 density {spherical scale enorb*1.5}
             }
         }
     }

#end