// Last edited on DATE TIME by stolfi
// Exemplo de arquivo de descricao de cena para POV-ray

// ======================================================================
#declare zoom = 2;

#declare ctr = < 0, 0, 0 >;
#declare camDir = < 1,-45, 20 >;

camera {
  location   ctr + 1.00*camDir
  right      1.20*z*zoom
  up         0.90*y*zoom
  sky        z
  look_at    ctr
}
 

// ======================================================================
// FONTES DE LUZ

light_source {
  10 * < 50, -10.0, +10.0 >              // Posição da lâmpada.
  color rgb 1.2 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < -50.0, 10.0, 70.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < 0.0, -10.0, 10.0 >             // Posição da lâmpada.
  color rgb 0.9 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

// ======================================================================
// DESCRIÇÃO DA CENA 
#declare C = 1/255;
background{ color rgb < 0.75, 0.80, 0.85 > }

#declare raio = 0.500;


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

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

#declare vermelho = 
  texture {
    pigment { color rgb < 1.0, 0.0, 0.0 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }
#declare verde = 
  texture {
    pigment { color rgb < 0.0, 1.0, 0.0 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }
#declare laranja = 
  texture {
    pigment { color rgb < 252*C, 200*C, 81*C > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare preto = 
  texture {
    pigment { color rgb < 0*C, 0*C, 0*C > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

// Objetos
// Os eixos para auxilio
#declare  eixo_x = 
   cylinder {
    < -50, 0, 0 >,
    < 50, 0, 0 >,
    0.1
    texture { vermelho }
  }
#declare  eixo_y = 
   cylinder {
    < -50, 0, 0 >,
    < 50, 0, 0 >,
    0.1
    texture { verde }
    rotate <0,0,90>
  }
#declare  eixo_z = 
   cylinder {
    < -50, 0, 0 >,
    < 50, 0, 0 >,
    0.1
    texture { azul }
    rotate <90,90,0>
  }

#declare eixos = 
union{
  object{eixo_x}
  object{eixo_y}
  object{eixo_z}
}

//O Chao
#declare chao =
box{
  <-50,-50,0>,
     <50,50,-1>
     texture {preto}
}


///////// BARATA ///////
#declare f=0.9;
#declare s=seed(23487564);
#declare counter=0;

#while ( counter < 6 )

//Angulos e posicoes
#declare ang_peh_y=-90 + 180*rand(s);
#declare ang_tibia_y=-45 + 45*rand(s);
#declare ang_tibia_x=-10 + 10*rand(s);
#declare ang_sub_coxa_x=-5 + 5*rand(s);
#declare ang_sub_coxa_y=-45 + 45*rand(s);
#declare ang_sub_coxa_z=-45 + 45*rand(s);
#declare ang_coxa_x=90 - 45*rand(s);
#declare ang_coxa_y=90 -60*rand(s);
#declare ang_coxa_z=0  -45*rand(s);


#declare pos_pata_sup=<7.3,0,12.5>;
#declare pos_pata_med=<8,0,0>;
#declare pos_pata_inf=<7.3,0,-13.5>;


// PEH
#declare peh = 
union{
  sphere{
    <0,0,0>, 1.5
    texture {vermelho}
  }
  box {
      <0,-2,1>,
      <8,2,-1>
      texture {amarelo}
  }
}

// TIBIA
#declare tibia = 
union{
  sphere{
    <0,0,0>,1.5
    texture{vermelho}
  }
  cylinder{
    <0,0,0>,
    <10,0,0>,
    1
    texture {amarelo}
  }
  object{
    peh
    rotate <0,ang_peh_y,0>
    translate <10,0,0>
  }
}

// SUB COXA

#declare sub_coxa = 
union{
  sphere{
    <0,0,0>,1.5
    texture{vermelho}
  }
  cylinder{
    <0,0,0>,
    <10,0,0>,
    1
    texture {amarelo}
  }
  object {
    tibia
    rotate <ang_tibia_x,ang_tibia_y,0>
    translate <10,0,0>
  }
}  

// COXA

#declare coxa=
union{
  cone{
    <0,0,0>,2.5
        <10,0,0>,1.5
        texture{ verde}
  }
  object { 
    sub_coxa
    rotate <ang_sub_coxa_x,
      ang_sub_coxa_y,
      ang_sub_coxa_z>
    translate <10,0,0>
  }
}


object {
  coxa
#switch ( counter )
#case (0)
  rotate<ang_coxa_x,ang_coxa_y,ang_coxa_z>
  translate pos_pata_inf
  scale<1,1,1>*f
#break
#case (1)
  rotate<ang_coxa_x,ang_coxa_y,ang_coxa_z>
  translate pos_pata_inf
  scale <-1,1,1>*f
  
#break
#case (2)
  rotate<ang_coxa_x,ang_coxa_y,ang_coxa_z>
  translate pos_pata_med
  scale<1,1,1>*f
#break
#case (3)
  rotate<ang_coxa_x,ang_coxa_y,ang_coxa_z>
  translate pos_pata_med
  scale <-1,1,1>*f
#break
#case (4)
  rotate<ang_coxa_x,ang_coxa_y,ang_coxa_z>
  translate pos_pata_sup
  scale<1,1,1>*f
#break
#case (5)
  rotate<ang_coxa_x,ang_coxa_y,ang_coxa_z>
  translate pos_pata_sup
  scale <-1,1,1>*f
#break
#end //switch  
}

#declare counter=counter+1;
#end //while


// CORPO
#declare corpo = 
union {
  sphere{
  <0,0,0>,8
  scale<1,0.3,3>*1.2
  texture {azul}
  }
  sphere{
  <0,0,0>,1
  texture{vermelho}
  translate<3,-3,23>
  scale<1,1,1>
  }
  sphere{
  <0,0,0>,1
  texture{vermelho}
  translate<3,-3,23>
  scale<-1,1,1>
  }
  cone{
  <0,0,0>,3
  <0,0,-2>,0
  texture{amarelo}
  scale<1,0.3,1>
  translate<0,-3,22>
  
  }
  
}


//------------------------




  
// Aqui está a cena, finalmente:

union{
  //object{eixos}
  object{corpo}  
  //object{coxa}
  //object{sub_coxa}
  // object{tibia}
  //object{peh}
  

  //object{chao}
}