#include "colors.inc"
#include "glass.inc"
#include "stones.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "shapesq.inc"
#include "metals.inc"
#include "rand.inc"


background { color White*0 }

light_source { <10,100,-1000> color White*1 parallel point_at <0,0,-100> shadowless }
light_source { <10,100,1000> color White*1 parallel point_at <0,0,-100> shadowless }

global_settings { ambient_light <1,1,1>*1 }

camera { location <0, 0, -20> look_at  <0, 0+0, 2> //rotate <0,30*7+90,0> rotate <90,0,0>
//rotate <0,120-10,0>  rotate <0,60,0> translate <0,0,100+100> rotate <0,30+30+60,0>  translate
<0,0,300>
}

#declare string_tex_1 = texture { pigment { rgbt <0,2,2,0.6> } };
#declare string_interior = interior
{ media
{ emission 10*2
  density
  { spherical density_map
    {
      [ 0 rgbt <0, 0, 0.5, 0> ]
      [ 0.25 rgbt <0, 0.4, 0.8, 0> ]
      [ 0.5 rgbt <0.2, 0.6, 1, 0> ]
      [ 0.75 rgbt <0.4, 0.8, 1, 0> ]
      [ 1.0 rgbt <0.5, 0.9, 1, 0> ]
    }
    //turbulence 1.5 //fireball
    //turbulence 0.2  //planetary nebula
    turbulence 0.1
    frequency 0.5
  } scale 5
}
};

#declare string = 0;
// set string = 0 for a closed string
// set string = 1 for an open string attached to one D-brane
// set string = 2 for an open string between two D-branes

#if(string = 0)
//Closed string

#declare pts = 36+5;
sphere_sweep { b_spline pts

#declare r = 0.05;
#declare A = 4;
#declare B = 4;
#declare P = 0;
#declare Q = 0;
#declare d = pi/3;

#declare C = 1;
#declare R = 2*pi*clock;
#declare S = -2*pi*clock;
#declare e = pi/9;
#declare f = pi/9;

#declare theta = 0;
#declare pt = 1;
#while(pt <= pts)

//<A*sin((theta/(d))*(pt)+P), B*cos((theta/(d))*(pt)+Q), C*sin((theta/(e))*(pt)+R)>, r //open ends
<A*sin((theta/(d))*(1)+P), B*cos((theta/(d))*(1)+Q), C*sin((theta/(e))*(1)+R) + C*sin((theta/f)+S)>, r //closed
ends
#declare theta = theta + ((2*pi)/36);

//<A*sin(theta + P), B*cos(theta + Q), 0>, r
//#declare theta = theta + ((2*pi)/pts);

#declare pt = pt + 1;
#end

//pigment { rgb <1,0,1> }
hollow texture { string_tex_1 } interior { string_interior }
rotate <40,0,0>
rotate <0,0,0>
translate <0,1,0>
scale 2
}
#end

#if(string = 1)
union{
//Open string on same brane
#declare pts = 36+5;
sphere_sweep { b_spline pts

#declare r = 0.05;
#declare A = 1;
#declare B = 1;
#declare P = 0;
#declare Q = 0;
#declare d = pi/3;

#declare C = 0;
#declare D = 0;
#declare R = 2*pi*clock;
#declare S = -2*pi*clock;
#declare rot = 360*clock;
#declare e = pi/3;
#declare f = pi/3;
#declare g = pi/3;

#declare theta = 0;
#declare X = 0;
#declare pt = 1;
#while(pt <= pts)

<X, A*sin((theta/(d))+R) + B*sin((theta/e)+S), C*sin((theta/(f))+R) + D*sin((theta/g)+S)>, r //closed ends
#declare theta = theta + ((4*pi)/36);
#declare X = X + 0.25;

#declare pt = pt + 1;
#end

hollow texture { string_tex_1 } interior { string_interior }
//rotate <40,0,0>
rotate <clock,0,0>
translate <-5,0,0>
scale 2
}

//D-branes
//plane { <1,0,0>, -10 pigment { rgb 3 } }
//plane { <1,0,0>, 10 pigment { rgb 5 } }

box { <0,10,10>, <-1,-10,-1> pigment { rgb 3 } scale <0.5,0.9,0.5> translate <-10,0,0> }
box { <0,-10,-1>, <1,10,10> pigment { rgb 3 } scale <0.5,0.9,0.5> translate <10,0,0> }

}
#end


#if(string = 2)
union{
//Open string between two branes
#declare pts = 36+5;
sphere_sweep { b_spline pts

#declare r = 0.05;
#declare A = 4;
#declare B = 4;
#declare P = 0;
#declare Q = 0;
#declare d = pi/3;

#declare C = 1;
#declare R = 2*pi*clock;
#declare S = -2*pi*clock;
#declare e = pi/6;
#declare f = pi/6;

#declare theta = 0;
#declare pt = 1;
#while(pt <= pts)

<A*sin((theta/(d))*(1)+P), B*cos((theta/(d))*(1)+Q), C*sin((theta/(e))*(1)+R) + C*sin((theta/f)+S)>, r //closed
ends
#declare theta = theta + ((1*pi)/36);

#declare pt = pt + 1;
#end

//pigment { rgb <1,0,1> }
hollow texture { string_tex_1 } interior { string_interior }
//rotate <40,0,0>
rotate <0,0,5>
translate <0,0,0>
scale 2
}

//D-brane
box { <0,10,10>, <-1,-10,-2> pigment { rgb 3 } scale <0.5,0.9,0.5> translate <0,0,0> }

//rotate <40,0,0>

}
#end