// Persistence of Vision Ray Tracer Scene Description File
// File: ?.pov
// Vers: 3.5
// Desc: Basic Scene Example
// Date: mm/dd/yy
// Auth: ?
//
/*
Antialias=on

Antialias_Threshold=0.2
Antialias_Depth=3
Input_File_Name=Joule_expansion.pov
Output_File_Name=JE

Initial_Frame=1
Final_Frame=400   
Initial_Clock=.0
Final_Clock=2

Cyclic_Animation=off
Pause_when_Done=off

+FC
*/
#version 3.5;

#include "colors.inc"
#include "rand.inc"
#include "textures.inc"
#include "metals.inc"
#include "mrg_misc2.inc"

global_settings {
  assumed_gamma 1.0
  ambient_light <1,1,1>*.7
}

#declare lclock=clock+.0;
//containers parameters
#declare L1=.5;
#declare T1=.2;

//atom parameters
#declare N =500;
#declare atom_r = array[N];
#declare atom_v = array[N];
#declare speed = 100;

//initialize the atoms
#if (frame_number != 0 & frame_number != 1)//is this test render or first frame?
     #include "joule_exp_scratch.inc"
#else
  #declare ic=0;
  #declare Stream=.111;
  #while(ic<N)
     #declare atom_r[ic]=VRand_In_Box(-L1/2, L1/2, Stream);
     #declare atom_v[ic]=VRand_On_Sphere(Stream);
     #declare ic=ic+1;
  #end
#end

//draw the atoms

#declare ic=0;
#while(ic<N)
     sphere {
          atom_r[ic], .005
          texture { 
               pigment { color Yellow } 
               finish{ambient .8 diffuse .2 phong 20}  
          } 
          no_shadow no_reflection
     }
     #declare ic=ic+1;
#end

//evolve the next state
#declare rightb=L1/2;
#if (lclock>T1)
     #declare rightb=5/2*L1;
#end     
#declare dt=.01;
#declare ic=0;
#while(ic<N)
     #declare oldr=atom_r[ic];
     #declare newv=atom_v[ic];
     #declare newr=atom_r[ic]+atom_v[ic]*dt;
     #if(newr.x<=-L1/2) //left
          #declare newr=<-L1-newr.x,newr.y,newr.z>;
          #declare newv=<-newv.x,newv.y,newv.z>; 
     #end
     #if(newr.x>=rightb) //right
          #declare newr=<2*rightb-newr.x,newr.y,newr.z>;
          #declare newv=<-newv.x,newv.y,newv.z>; 
     #end
     #if(newr.y<=-L1/2) //bottom
          #declare newr=<newr.x,-L1-newr.y,newr.z>;
          #declare newv=<newv.x,-newv.y,newv.z>; 
     #end
     #if(newr.y>=L1/2) //top
          #declare newr=<newr.x,L1-newr.y,newr.z>;
          #declare newv=<newv.x,-newv.y,newv.z>; 
     #end
     #if(newr.z<=-L1/2) //front
          #declare newr=<newr.x,newr.y,-L1-newr.z>;
          #declare newv=<newv.x,newv.y,-newv.z>; 
     #end
     #if(newr.z>=L1/2) //back
          #declare newr=<newr.x,newr.y,L1-newr.z>;
          #declare newv=<newv.x,newv.y,-newv.z>; 
     #end
     #declare atom_r[ic]=newr;
     #declare atom_v[ic]=newv;
     #declare ic=ic+1;
#end

#fopen next "joule_exp_scratch.txt" write
#declare ic=0;
#while(ic<N)
     #write (next,ic," , ",atom_r[ic]," , ",atom_v[ic]," , \r\n")
     #declare ic=ic+1;
#end
#fclose next
#fopen outinc "joule_exp_scratch.inc" write
#declare ic=0;
#while(ic<N)
     #write (outinc,"#declare atom_r[",ic,"]=",  atom_r[ic],";  \r\n")
     #write (outinc,"#declare atom_v[",ic,"]=",  atom_v[ic],";  \r\n")
     #declare ic=ic+1;
#end
#fclose outinc


// ----------------------------------------

camera {
  location  <L1, 0, -2.0>
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <L1, 0.0,  0.0>
}


light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <-30, 50, -40>
}

// ----------------------------------------
#declare boxthickness=.005;
#declare panel = box{-(L1/2+boxthickness)*<1,1,1>,L1/2*<-1,1,1>+boxthickness*(y+z)}
#declare halfpanel=box{L1/2*<0,-1,-1>, L1/2*z+boxthickness*<1,0,0> 
     translate L1/2*x 
     translate -y*L1/2*ltrans((lclock-T1)/.0001)
     }
union{
     object{panel}
     object{panel rotate z*90}
     object{panel rotate z*-90}
     object{panel rotate y*90}
     //object{panel rotate y*180}
    object{panel rotate z*90 translate L1*x}
     object{panel rotate z*-90 translate L1*x}
     object{panel rotate y*90 translate L1*x}
    object{panel rotate z*90 translate 2*L1*x}
     object{panel rotate z*-90 translate 2*L1*x}
     object{panel rotate y*90 translate 2*L1*x}
     object{panel rotate y*180 translate 2*L1*x}
     object{halfpanel}
     object{halfpanel scale <1,-1,1>}
     texture{T_Silver_3A}
     no_shadow no_reflection
}




