// 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;
// ==== Standard POV-Ray Includes ====
#include "colors.inc"	  // Standard Color definitions
#include "textures.inc"	  // Standard Texture definitions
#include "functions.inc"  // internal functions usable in user defined functions
#include "colors.inc"
// some standard finishes
#include "finish.inc"
#include "woods.inc"
#include "glass.inc"
// macros for generating various shapes
// 
#include "shapes.inc"

global_settings {
  assumed_gamma 1.0
}
#declare trans = function(tt) { (1-cos(pi*max(min(tt,1),0)))/2 }  //smoothed transition
#declare ltrans=function(tt) { max(min(tt,1),0) }                 //linear transition 

#declare T1=1;  //start moving charge in
#declare dT1=3;  
#declare T2=T1+dT1+1;  //rotate vantage point
#declare dT2=3;  
#declare T3=T2+dT2+1;  //extend grounding wire
#declare dT3=3;  
#declare T4=T3+dT3;  //shift charge
#declare dT4=3;  
#declare T5=T4+dT4+1;  //retract grounding wire
#declare dT5=3;  
#declare T6=T5+dT5+1;  //rotate vantage point
#declare dT6=3;  
#declare T7=T6+dT6+1;  //remove charge
#declare dT7=3;  

#declare lclock=clock+.00;
#declare ycmin=2;
#declare aymax=1/ycmin;
#declare yc=10-(10-ycmin)*(trans((lclock-T1)/dT1)-trans((lclock-T7)/dT7));
#declare cpos = vrotate(<0,1,-8>, 360*(  trans((lclock-T2)/dT2)+trans((lclock-T6)/dT6)  ) *y);

#declare QW=90*(  trans((lclock-T3)/dT3)-trans((lclock-T5)/dT5) ); 

#declare Qratio = - aymax*ltrans((lclock-T4)/dT4);
#declare Qcurrent = 360*ltrans((lclock-T4)/(dT4*4/3)); //allow exta time for last "charge" to flow out of wire

   

// ----------------------------------------
background{color rgb Gray*.0}
camera {
  location  cpos
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <0.0, 0.0,  0.0>
}


light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <-30, 30, -30>
}


#declare ay=1/yc;
#declare ff=function(x,y,z,aay){-(aay*(1-aay*aay))/(1+aay*aay-2*aay*x/sqrt(x*x+y*y+z*z))+aay+Qratio}
 

#declare fscale=.5/abs(ff(1,0,0,aymax));

sphere {0,1                                      //conducting sphere
       pigment { function {.5+ff(x,y,z,ay)*fscale}
         color_map { [0.0 rgb <1.2,0,0>]
                      [.5 rgb .1]
                     [1.0 rgb <0,0,1.2>]
         }
       }
     rotate y*0
     finish{Luminous}
     no_reflection no_shadow
}

sphere {0,.98                                       //conducting sphere "body"
  texture{
     pigment{color rgbt .75*<1,1,1,0>+<0,0,0,.9>}
     finish{Shiny}
   }
}

cylinder{-y,-3*y, .15 texture{T_Wood1 rotate x*90 translate 2*x}}  //conducting sphere support post
sphere{0,.1 pigment{color rgb <0,0,1>} finish{Luminous} translate yc*x}    //charge


 box{1,-1 scale <5,.001,5> translate -3*y        //table
      pigment {
               checker White Black
       }

 }


//conducting wire

intersection{                                                                  
     torus{3,.025}
     Wedge(QW)       //this angle raises and loweres the the grounding wire
     rotate -y*90
     rotate -x*90
     
     translate -y*3-x
       texture{
          pigment{color rgbt .5*<1,1,1,0>+<0,0,0,.9>}
          finish{Shiny}
        }
}     

#declare QQ=90;

intersection{
     difference{
          torus{3,.0249}
          Wedge(92)
     texture{
          pigment{bozo   turbulence .2
               color_map { 
                    [0.0 rgb <0,0,1>]
                    [0.3 rgb <0,0,1>]
                    [0.8 rgbt <0,0,0,1.0>]
                    [1 rgbt <0,0,0,1.0>]

               }
                    
               
          }
          finish{Luminous}
          scale .05
     }
     rotate -y*Qcurrent  //rotate through 360 to get current flow
     }     
     Wedge(QQ)       
     rotate -y*90
     rotate -x*90
     translate -y*3-x
}     
/* */