// 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"
#include "golds.inc"
#include "metals.inc"
#include "shapes.inc"

global_settings {
  assumed_gamma 1.0
  max_trace_level 6
}
#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=9;  //start moving charge in
#declare dT1=4;  
#declare T2=20;  //rotate vantage point at 
#declare dT2=6;  
#declare T3=27;  //extend grounding wire
#declare dT3=3;  
#declare T4=30;  //flow charge
#declare dT4=6;  
#declare T5=39;  //retract grounding wire
#declare dT5=3;  
#declare T6=41;  //rotate vantage point
#declare dT6=6;  
#declare T7=46;  //remove charge
#declare dT7=4;  

#declare lclock=clock+0.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.5,-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>
}



// create a regular point light source
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate <-30, 40, -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 <2,0>]
                     [0.25 rgb <1,0>]
                      [.5 rgbt <0,0,0,1>]
                     [.75 rgb <.0,.0,1>]
                     [1.0 rgb <.0,.0,2>]
         }
       }
            finish{Luminous}
}
/**/


sphere {0,.98    
texture{T_Chrome_1B}
}                                     //conducting sphere "body"


 sphere                              // surface charge as media
 { 0,1.02 pigment { rgbt 1 } hollow
   interior
   { media
     { emission 1
       density
       {function {.5+ff(x,y,z,ay)*fscale}
         color_map { [0.0 rgb <2,0>]
                     [0.25 rgb <1,0>]
                      [.5 rgbt <0,0,0,1>]
                     [.75 rgb <.0,.0,1>]
                     [1.0 rgb <.0,.0,2>]         }
       }
     }
  }
 no_shadow
 }
/**/  
  
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 <4.99,.001,4.99> translate -3*y        //table
      pigment {
               checker White color rgb <.1,.1,.13>*6
        }
       finish{Shiny}
 }


//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
}     
/* */