// PoVRay 3.7 Scene File " ... .pov"
// author:  ...
// date:    ...
//--------------------------------------------------------------------------
#version 3.7;
global_settings{ assumed_gamma 1.0 }
//--------------------------------------------------------------------------
#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "metals.inc"
#include "golds.inc"
#include "stones.inc"
#include "woods.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "functions.inc"
#include "math.inc"
#include "transforms.inc"
#include "mrg_misc3.inc"
#include "platonic_solids.inc"

#declare lclock=clock+0;

//move test charge around  2-10,10-18 
    //rotate in screen plane with varying distance then corkscrew down

#declare test_r=vrotate((1.2+.4*sin(3*pi*trans((lclock-2)/8)))*x, 390*trans((lclock-2)/8)*z); 
#declare test_r=vrotate(test_r, 540*trans((lclock-10)/8)*y)-1.5*y*trans((lclock-10)/8); 

//fade in efield marker array 20-24
#declare t2F=trans((lclock-20)/4);


// rotate perspective  26-36

#declare cpos= vrotate (<.5, 2+2*sin(pi*trans((lclock-26)/10)), 7>, 360*trans((lclock-26)/10)*y);


//fade in efield lines phade out efied markers 36-40
#declare t4F=trans((lclock-36)/4); 

//and rotate perspective   45-55

#declare cpos= vrotate (cpos, 360*trans((lclock-45)/10)*y)+2*sin(pi*trans((lclock-45)/10))*y;









// perspective (default, not required) camera
camera {
  perspective
  location  cpos
  look_at   <0, 0,  0>
  right     -x*image_width/image_height  // aspect &RH coords
  // direction z                        // direction and zoom
  // angle 67                           // field (overides direction zoom)
}
// create a regular point light source
light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate 5*<-20, 40, 20>
}


#declare p_texture= texture {pigment{color rgb <.7,.0,.0>} finish{Shiny}} ;
#declare test_texture= texture {pigment{color rgb .5*<1,.025,.10>} finish{Shiny}} ;
#declare n_texture= texture {pigment{color rgb <.0,.0,.7>} finish{Shiny}} ;
#declare Efieldlinetexture=texture{pigment{color rgb <1,.15,.1>} finish{Shiny}}; 
#declare Bfieldlinetexture=texture{pigment{color rgb <.1,.1,1>} finish{Luminous}}; 
#declare charge_radius=.12;
#declare test_charge_radius=.4*charge_radius;


//Make_Vector(vec,head_length,post_diameter,head_diameter)

#declare post_diameter=.2*test_charge_radius;
#declare head_diameter=3*post_diameter;
#declare head_length=3*head_diameter;


//charge
sphere { <0,0,0>, charge_radius texture{p_texture}}  // end of sphere ----------------------------------- 

//testcharge
#declare E=.3*test_r/pow(vlength(test_r),3);
sphere { <0,0,0>, test_charge_radius texture{test_texture} translate test_r}  // end of sphere ----------------------------------- 
object{Make_Vector(E,head_length,post_diameter,head_diameter) translate test_r texture{Efieldlinetexture}}    


#if((t2F>0)&(t4F<1))
    #declare ds=.75;
    #declare smax=3 ;
    
    #declare snowx=-smax;
    #while (snowx<= smax)
        #declare snowy=-smax;
        #while (snowy<= smax)
            #declare snowz=-smax;
            #while (snowz<= smax)
                #declare snow=<snowx,snowy,snowz>;
                #if(vlength(snow)>.5*ds)
                    #declare E=.3*snow/pow(vlength(snow),3);
                    #declare Etexturefadein=texture{pigment{color rgbt <1,.15,.1,1-t2F+t4F>} finish{Shiny}}; 
    
                    object{Make_Vector(E,head_length,post_diameter,head_diameter) translate snow texture{Etexturefadein}}    
                    
                
                #end
                #declare snowz=snowz+ds;
            #end
            #declare snowy=snowy+ds;
        #end
        #declare snowx=snowx+ds;
    #end
#end

//field lines
#if(t4F>0)
    #declare iv=0;
    #while (iv<20)
        #declare Etexturefadein=texture{pigment{color rgbt <1,.15,.1,1-t4F>} finish{Shiny}}; 
    
        object{Make_Vector(PDvertex[iv],head_length,post_diameter,head_diameter) texture{Etexturefadein}}
        cylinder{PDvertex[iv],4*PDvertex[iv], post_diameter texture{Etexturefadein}}
    
        #declare iv=iv+1;
    #end
#end


