// Last edited on 2013-12-11 11:19:19 by stolfilocal
// Processed by remove-cam-lights

background{ color rgb < 0.75, 0.80, 0.85 > }

#declare tx_azul =
  texture{
    pigment{ color rgb < 0, 0, 1 > }
  }

#declare tx_vermelho =
  texture{
    pigment{ color rgb < 1,0,0 > }
  }

#declare tx_verde =
  texture{
    pigment{ color rgb < 0,1,0 > }
  }

#declare tx_plastico =
  texture{
    pigment{ color rgb < 0.10, 0.80, 1.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_fosca =
  texture{
    pigment{ color rgb < 1.00, 0.80, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_espelho =
  texture{
    pigment{ color rgb < 1.00, 0.85, 0.30 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

#declare tx_vidro =
  texture{
    pigment{ color rgb < 0.85, 0.95, 1.00 > filter 0.70 }
    finish{ diffuse 0.03 reflection 0.25 ambient 0.02 specular 0.25 roughness 0.005 }
  }

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#macro Interpola2(p0,p1,tt)
((1-tt)*p0 + tt*p1)
#end

#macro Interpola4(p0,p1,p2,p3,tt)
  #local p01 = Interpola2(p0,p1,tt);
  #local p12 = Interpola2(p1,p2,tt);
  #local p23 = Interpola2(p2,p3,tt);
  #local p012 = Interpola2(p01,p12,tt);
  #local p123 = Interpola2(p12,p23,tt);
  Interpola2(p012,p123,tt)
#end

#macro SphereLine2(p0,p1,r0,r1,n)
  union {
    #declare Index = 0;
    #while(Index < n)
    sphere { <0,0,0>, Interpola2(r0,r1,Index/n) translate Interpola2(p0,p1,Index/n) }
    #declare Index = Index + 1;
    #end
  }
#end

#macro SphereLine4(p0,p1,p2,p3,r0,r1,r2,r3,n)
  union {
    #declare Index = 0;
    #while(Index < n)
    sphere { <0,0,0>, Interpola4(r0,r1,r2,r3,Index/n) translate Interpola4(p0,p1,p2,p3,Index/n) }
    #declare Index = Index + 1;
    #end
  }
#end

#macro Tentacle(p0,p1,p2,p3,p4,p5)
  #local SIZE = 100;
  #local p23 = (p2+p3)/2;
  #local r23 = (0.5+0.3)/2;
  union {
    SphereLine4(p0,p1,p2,p23,0.7,0.5,0.5,r23,SIZE)
    SphereLine4(p23,p3,p4,p5,r23,0.3,0.2,0.1,SIZE)
  }
#end

#macro Tentacle_animado(param0, param1, param2, param3, tempo)
  #local N = 6;
  #local param = array[N];
  #local i = 0;
  #while (i < N)
    #local param[i] = Interpola4(param0[i], param1[i], param2[i], param3[i],tempo);
    #local i = i + 1;
  #end
  Tentacle (param[0],param[1],param[2],param[3],param[4],param[5])
#end

#macro Polvo(n,ss,ss2)
  union {
    object { SphereLine2(<0,0,1>,<0,0,12>,2,4,100) scale <ss,ss,ss> texture { tx_azul } }
    #declare Angle = 0;
    #while( Angle < 360 )
    object { Tentacle(<2,0,0>,<3,0,6>,<5,0,5>,<6,0,0>,<8,0,-3>,<10,0,-2>) rotate <0,0,Angle> scale<ss2,ss2,ss2> texture { tx_azul } }
    #declare Angle = Angle + 360/n;
    #end
  }
#end

#macro Polvo_Animado()
#local n = 4;
  union {
    object { SphereLine2(<0,0,1>,<0,0,12>,2,4,100)  texture { tx_vermelho } }
    #declare Angle = 0;
    #local pos1 = array[6]   {<2,0,0>,<3,0,6>,<5,0,5>,<6,0,0>,<8,0,-3>,<10,0,-2>}
    #local pos2 = array[6]   {<2,0,0>,<3,0,4>,<5,0,3>,<6,0,0>,<8,0,2>,<10,0,6>};
    #local pos3 = array[6]   {<2,0,0>,<3,0,4>,<5,0,3>,<6,0,0>,<8,0,2>,<10,0,6>};

    #while( Angle < 360 )
      object { Tentacle_animado(pos1, pos2, pos3, pos1, clock)
      rotate <0,0,Angle> scale<2,2,2> texture { tx_vermelho } }
      #declare Angle = Angle + 360/n;
    #end
  }

#end

#include "eixos.inc"

union{
  object { Polvo_Animado() }
}

#include "camlight.inc"
#declare centro_cena = < -0.20, 0.20, 1.00 >;
#declare raio_cena = 35.0;
#declare dir_camera = < 10.00, 5.00, 7.00 >;
#declare dist_camera = 30.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)