#include "colors.inc"
#include "stones.inc"
#include "textures.inc"

// Trabalho 2 de MC930

// ======================================================================
// CÂMERA 

camera {
  location  < 50.00, 60.00, 30.00 >  // Posição do observador.
  right     -0.75*x                // Largura RELATIVA da imagem.
  up        1.00*y                // Altura RELATIVA da imagem.      
  sky       z                      // Qual direção é "para cima"?
  look_at   < 0.00, 0.00, 0.00 >  // Para onde a câmera está apontando.
} 
// Nota: os parâmetros "right" e "up" devem ter a mesma proporção
// que os parâmetros ${WIDTH} e ${HEIGHT} no Makefile.

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

light_source {
  10 * < +50.0, +30.0, +50.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, +10.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

// ======================================================================
// DESCRIÇÃO DA CENA 

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

#declare dedo1 =
union {
  //Dedo 1
  sphere{
      < 0, 2.5, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 0, 2.5, 0>,     // Center of one end
    < 1, 2.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Cyan} }
  }
  sphere{
      < 1, 2.5, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 1, 2.5, 0>,     // Center of one end
    < 2, 2.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Green} }
  }
  sphere{
      < 2, 2.5, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 2, 2.5, 0>,     // Center of one end
    < 2.5, 2.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Blue} }
  }
  sphere{
      < 2.5, 2.5, 0>, 0.5
    texture { pigment {color Blue}}
  }

}
#declare dedo2 =
union {
  sphere{
      < 0, 1, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 0, 1, 0>,     // Center of one end
    < 1.2, 1, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Cyan} }
  }
  sphere{
      < 1.2, 1, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 1.2, 1, 0>,     // Center of one end
    < 2.4, 1, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Green} }
  }
  sphere{
      < 2.4, 1, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 2.4, 1, 0>,     // Center of one end
    < 3.1, 1, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Blue} }
  }
  sphere{
      < 3.1, 1, 0>, 0.5
    texture { pigment {color Blue}}
  }

}
#declare dedo3 =
union {
  sphere{
      < 0, -0.5, 0>, 0.55
    texture { pigment {color Brown}}
  }

  cylinder {
    < 0, -0.5, 0>,     // Center of one end
    < 1.3, -0.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Cyan} }
  }
  sphere{
      < 1.3, -0.5, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 1.3, -0.5, 0>,     // Center of one end
    < 2.6, -0.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Green} }
  }
  sphere{
      < 2.6, -0.5, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 2.6, -0.5, 0>,     // Center of one end
    < 3.3, -0.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Blue} }
  }
  sphere{
      < 3.3, -0.5, 0>, 0.5
    texture { pigment {color Blue}}
  }

}
#declare dedo4 =
union {
  sphere{
      < 0, -2, 0>, 0.55
    texture { pigment {color Brown}}
  }

  cylinder {
    < 0, -2, 0>,     // Center of one end
    < 1.2, -2, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Cyan} }
  }
  sphere{
      < 1.2, -2, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 1.2, -2, 0>,     // Center of one end
    < 2.4, -2, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Green} }
  }
  sphere{
      < 2.4, -2, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 2.4, -2, 0>,     // Center of one end
    < 3.1, -2, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Blue} }
  }
  sphere{
      < 3.1, -2, 0>, 0.5
    texture { pigment {color Blue}}
  }
}
#declare dedo5 =
union {
  sphere{
      <-0.2, -3, 0>, 0.55
    texture { pigment {color Brown}}
  }

  cylinder {
    < -0.2,  -3, 0>,     // Center of one end
    <  0.4, -4, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Cyan} }
  }
  sphere{
      < 0.4, -4, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 0.4, -4, 0>,     // Center of one end
    < 1.0, -5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Green} }
  }
  sphere{
      < 1.0, -5, 0>, 0.55
    texture { pigment {color Brown}}
  }
  cylinder {
    < 1.0, -5, 0>,     // Center of one end
    < 1.3, -5.5, 0>,     // Center of other end
    0.5            // Radius
    texture { pigment {color Blue} }
  }
  sphere{
      < 1.3, -5.5, 0>, 0.5
    texture { pigment {color Blue}}
  }

}

#if (clock < 0.5)
  #declare delta = 90*clock;
#else
  #declare delta = 45;
#end

#declare mao = 
union{

  box {
    < 0, -3, -1>,  // Near lower left corner
    < 6, 3, 1>   // Far upper right corner
    texture { pigment {color Gray} }
  }

  //Dedo 1
  object {dedo1
    rotate delta*y
    translate 6*x
  }

  //Dedo 2
  object {dedo2
    rotate delta*y
    translate 6*x
  }

  //Dedo 3
  object {dedo3
    rotate delta*y
    translate 6*x
  }
 
  //Dedo 4
  object {dedo4
    rotate delta*y
    translate 6*x
  }

  //Dedo 5
  object {dedo5
    rotate delta*y
    translate 6*x
  }

  //Articulacao
  sphere{
    <0,0,0>,
    3
    texture {pigment {color Pink}}
  }

}

#if (clock < 0.5)
  #declare alfa = 60*clock;
#else
  #declare alfa = 30;
#end

#if (clock < 0.5)
#declare beta = (90*clock - 45);
#else
  #declare beta = 0;
#end

#declare gama = (90 - 180*clock);

#declare antebraco =
union {
  sphere{
    <0,0,0>,
    3
  }
  cylinder {
    <0,0,0>,
    <12,0,0>,
    3
  }
  object {
    mao
    rotate -90*x
    rotate -alfa*z
    translate 12*x
  }
  texture {pigment {color Pink}}

}

#declare braco =
union{
  sphere{
    <0,0,0>,
    5
  }
  cylinder {
    <0,0,0>,
    <15,0,0>,
    3
  }
  object {
    antebraco
    rotate beta*y
    translate 15*x

  }
  texture {pigment {color Pink}}

}

//Braços
union {
  object {braco
    translate 10*y
    rotate gama*y

  }
  object {braco
    translate 10*y
    rotate gama*y
    scale -1*y
  }
}

//Criminoso
cylinder {
  <27,0,-4>,
  <27,0, 8>,
  7
  texture {pigment {color Red}}
  #if (clock > 0.5)
    rotate ((clock-0.5)*2)*-90*y
  #end
}


//Corpo
cylinder {
  <0,0,5>,
  <0,0,-15>,
  10
  texture {pigment {color Pink}}
}
//Pescoço
cylinder {
  <0, 0, 5>,
  <0, 0, 7>,
  2
  texture {pigment {color Pink}}
}
//Cabeça
sphere {
  <0,0,13>
  6
  texture {pigment {color Pink}}
}