#include "colors.inc"
#include "shapes.inc"
#include "math.inc"
#include "textures.inc"	  // Standard Texture definitions
#include "functions.inc"  // internal functions usable in user defined functions
#include "jbessel.inc"

global_settings
{
ambient_light rgb .2*<1, 1, 1>              // background light
// used in global_settings, sets image gamma in relation to display gamma
  assumed_gamma 1.0
}
background {color rgb <.7, .7, .7>}
#declare lclock=clock+.25;             
#declare amp=.3*cos(2*pi*lclock);
#declare amp2=.3*sin(2*pi*lclock);

#declare m=1;
#declare n=3;
#declare arr = function(xx,zz) {sqrt(xx*xx+zz*zz) }
//#declare rho = function(r,fee) { Jbes(m,r*Jbzeroes[m][n-1])*cos(m*fee) }
//#declare myiso=function(xx,zz) {rho(arr(xx,zz),atan2(zz,xx)) }

//test besseler
#declare x_function = function(s) {s }
#declare y_function = function(s) {amp*jbes[m](s*Jbzeroes[m][n-1]) }
#declare z_function = function(s) {0 }
/*#declare s_start=0;
#declare s_end=1;
#declare s_nseg=80;
#declare cyl_width=.02;
#declare s_count=1;                                                  
#declare s_ds=(s_end-s_start)/(s_nseg);
#declare temp_v1=<x_function(s_start),y_function(s_start) ,z_function(s_start)>;

#declare curve_obj= union{
        #while (s_count <= s_nseg)                                                  
                #declare s_this=s_start+s_count*s_ds;
                #declare temp_v2=<x_function(s_this),y_function(s_this) ,z_function(s_this)>;
                #cylinder{ temp_v1,temp_v2,cyl_width}
                #declare temp_v1=temp_v2;
                #declare s_count=s_count+1;
        #end
        texture {Cork scale .02}
}
object{curve_obj}
*/
                
isosurface {
        function {
                 amp*jbes[m](arr(x,z)*Jbzeroes[m][n-1])*cos(m*atan2(z,x))
                +amp2*jbes[m](arr(x,z)*Jbzeroes[m][n-1])*sin(m*atan2(z,x))-y 
                //amp*y_function(arr(x,z))*cos(m*atan2(z,x)) -y
               
                }   // isosurface y =  sum of terms above
                
          open                             // don't include bounding box in shape
          contained_by { sphere { 0, 1 } }       // dimensions of the bounding box
        max_gradient 5
          accuracy      0.001              // accuracy of calc for surface rendering

                  texture {
  pigment {          // (---surface color---)
 Blue  }
  finish {           // (---surface finish---)
    ambient 0.2
    specular 0.6     // shiny
    phong .2}
}

         
}

/* camera is far away with narrow FOV to reduce distortion */
camera {
    location 10*<-.0, .2 ,-1>
    look_at  <0, 0, 0>
    angle 14
}
// An area light (creates soft shadows)
// WARNING: This special light can significantly slow down rendering times!
light_source {
  0*x                 // light's position (translated below)
  color rgb 1.0       // light's color
  area_light
  <2, 0, 0> <0, 0, 2> // lights spread out across this distance (x * z)
  4, 4                // total number of lights in grid (4x*4z = 16 lights)
  adaptive 0          // 0,1,2,3...
  jitter              // adds random softening of light
  circular            // make the shape of the light circular
  orient              // orient light
  translate <0, 20, -4>   // <x y z> position of light
}
// create a regular point light source
light_source {
  0*x                  // light's position (translated below)
  color rgb <.5,.5,1>    // light's color
  translate 5*<-0, -40, -20>
}

#declare rim=.015;
torus { 1, rim texture {Brushed_Aluminum scale .1}}

