// Last edited on DATE TIME by USER
// Processed by remove-cam-lights

#include "eixos.inc"
#include "camlight.inc"
#declare centro_cena = < 2.00, 0.00, +3.00 >;
#declare raio_cena = 15.0;
#declare dir_camera = < 1.00, 7.00, 5.00 >;
#declare dist_camera = 50.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)

background{ color rgb < 0.50, 0.50, 0.50 > }

#declare vermelho_fosco = texture
{
  pigment{ color rgb <1.00, 0.00, 0.00>}
  finish { diffuse 1 specular 0.2 }
}

#declare verde_fosco = texture
{
  pigment{ color rgb <0.00, 0.70, 0.00>}
  finish { diffuse 1 specular 0.2 }
}

#declare verde_escuro = texture
{
  pigment{ color rgb <0.00, 0.30, 0.00>}
  finish { diffuse 1 specular 0.2 }
}

#declare azul_fosco = texture
{
  pigment{ color rgb <0.00, 0.00, 1.00>}
  finish { diffuse 1 specular 0.2 }
}

#declare branco_fosco = texture
{
  pigment{ color rgb <1.00, 1.00, 1.00>}
  finish { diffuse 1 specular 0.2 }
}

#declare preto_fosco = texture
{
  pigment{ color rgb <0.00, 0.00, 0.00>}
  finish { diffuse 1 specular 0.2 }
}

#declare cinza_fosco = texture
{
  pigment{ color rgb <0.40, 0.40, 0.40>}
  finish { diffuse 1 specular 0.2 }
}

#declare marrom_fosco = texture
{
  pigment{ color rgb <0.60, 0.30, 0.20>}
  finish { diffuse 1 specular 0.2 }
}

#declare amarelo_fosco = texture
{
  pigment{ color rgb <1.00, 1.00, 0.00>}
  finish { diffuse 1 specular 0.2 }
}

#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
  }

#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 chao =
  box{ <-100,-100,-1>, <+100,+100,0>}

#declare num_quadros = 9;

#declare ang_corpo = array[num_quadros] {0,0,0,90,180,180,180,270,0};
#declare ang_braco_esq = array[num_quadros] {0,180,180,180,180,  0,0,0,0};
#declare ang_braco_dir = array[num_quadros] {0,  0,180,180,180,180,0,0,0};
#declare ang_antebraco_esq = array[num_quadros] {90, 0, 0,0,0,90,90,90,90};
#declare ang_antebraco_dir = array[num_quadros] {90,90, 0,0,0, 0,90,90,90};
#declare ang_perna_esq = array[num_quadros] {0, 90, 90, 0, 0, 90,90,0,0};
#declare ang_perna_dir = array[num_quadros] {0,  0, 90, 0, 0,  0,90,0,0};
#declare tempo = array[num_quadros] {0.0, 0.125, 0.250, 0.375, 0.500, 0.625, 0.750, 0.825, 1.000};

#macro interpola (f0,v0,f1,v1,f)
  #local ss = (f-f0)/(f1-f0);
  #local rr = 1 - ss;
  (rr*v0 + ss*v1)
#end

#macro quadro_anterior(fase)
  #local i=0;
  #while (i < (num_quadros-1))
    #if ((tempo[i] <= fase) & ((i = num_quadros-1) | (tempo[i+1] >= fase)))
      #local resp = i;
    #end
    #local i=i+1;
  #end
  resp

#end

#macro coelho_dancando (fase)
  #local i = quadro_anterior(fase);

  #local corpo     = interpola (tempo[i],ang_corpo[i],tempo[i+1],ang_corpo[i+1],fase);
  #local braco_esq = interpola (tempo[i],ang_braco_esq[i],tempo[i+1],ang_braco_esq[i+1],fase);
  #local braco_dir = interpola (tempo[i],ang_braco_dir[i],tempo[i+1],ang_braco_dir[i+1],fase);
  #local antebraco_esq = interpola (tempo[i],ang_antebraco_esq[i],tempo[i+1],ang_antebraco_esq[i+1],fase);
  #local antebraco_dir = interpola (tempo[i],ang_antebraco_dir[i],tempo[i+1],ang_antebraco_dir[i+1],fase);
  #local perna_esq = interpola (tempo[i],ang_perna_esq[i],tempo[i+1],ang_perna_esq[i+1],fase);
  #local perna_dir = interpola (tempo[i],ang_perna_dir[i],tempo[i+1],ang_perna_dir[i+1],fase);

  object{coelho(<0,0,0>, 2, corpo, braco_esq, braco_dir, antebraco_esq, antebraco_dir,
                perna_esq, perna_dir, 0, 0) }
#end

#macro braco (tamanho,pos_braco,ang_y_braco,ang_x_braco,ang_antebraco)
  union
  {
    sphere{<0,0,0>,tamanho/4 texture {branco_fosco}}
    cone {<0,0,0>,tamanho/7,<0,0,-tamanho>,tamanho/10 texture {branco_fosco}}

    object{antebraco (tamanho,ang_antebraco) }
    rotate ang_y_braco*y
    rotate ang_x_braco*x
    translate <0,tamanho/5,2*tamanho>
    translate <pos_braco,0,0>
  }
#end

#macro antebraco (tamanho,ang_antebraco)
  union
  {
    cone{<0,0,0>,tamanho/10,<0,0,-tamanho*2/3>,tamanho/15 texture{branco_fosco}}
    sphere{<0,0,-tamanho*2/3>,tamanho/5 texture {branco_fosco}}
    rotate ang_antebraco*x
    translate <0,0,-tamanho>
  }
#end

#macro perna(tamanho, pos_perna, ang_perna,ang_canela,ang_pe)
  union
  {
    sphere{<0,0,0>,tamanho*2/3 texture {branco_fosco}}
    cone{<0,0,-tamanho/3>,tamanho/3,<0,0,-tamanho*3/2>,tamanho/4 texture{branco_fosco}}

    object{canela (tamanho,ang_canela,ang_pe) }
    rotate ang_perna*x
    translate pos_perna
  }
#end

#macro canela (tamanho,ang_canela,ang_pe)
  union
  {
    cone{<0,0,0>,tamanho/4,<0,0,-tamanho>,tamanho/6 texture{branco_fosco}}
    object{pe (tamanho,ang_pe) }
    rotate ang_canela*x
    translate <0,0,-tamanho*3/2>

  }
#end

#macro pe (tamanho,ang_pe)
  difference
  {
    cone{<0,0,0>, tamanho/6 , <0,tamanho*3/2,0>, tamanho/4 texture{branco_fosco}}
    box{<-tamanho/2,tamanho*2,-tamanho/2>, <tamanho/2,-tamanho/5,0>  texture {branco_fosco}}
    rotate ang_pe*x
    translate <0,0,-tamanho>
  }
#end

#macro coelho (posicao, tamanho , ang_corpo, ang_braco_esq, ang_braco_dir, ang_antebraco_esq, ang_antebraco_dir,
              ang_perna_esq, ang_perna_dir, ang_canela, ang_pe)

  union
  {

    sphere {<0,0,0>,tamanho texture {branco_fosco}}
    cone {<0,0,0>,tamanho,<0,0,tamanho*2>,tamanho/2 texture {branco_fosco}}
    sphere{<0,0,tamanho*2.5>,tamanho*2/3 texture {branco_fosco}}

    intersection
    {
      sphere{<0,0,tamanho*2.5+0.001>,tamanho*2/3 texture {vermelho_fosco}}
      cylinder{<-tamanho/3,0,tamanho*2.6+0.001>, <-tamanho/3,2*tamanho,tamanho*2.6+0.001>, tamanho/10 texture {vermelho_fosco}}
    }

    intersection
    {
      sphere{<0,0,tamanho*2.5+0.001>,tamanho*2/3 texture {vermelho_fosco}}
      cylinder{<tamanho/3,0,tamanho*2.6+0.001>, <tamanho/3,2*tamanho,tamanho*2.6+0.001>, tamanho/10 texture {vermelho_fosco}}
    }

    intersection
    {
      sphere{<0,0,tamanho*2.4+0.001>,tamanho*2/3 texture {preto_fosco}}
      cylinder{<0,0,tamanho*2.4+0.001>, <0,2*tamanho,tamanho*2.4+0.001>, tamanho/6 texture {preto_fosco}}
    }

    cone {<-tamanho/5,0,tamanho*3>,tamanho/5,<-tamanho/5,0,tamanho*3.5>,0 texture {branco_fosco}}
    cone {< tamanho/5,0,tamanho*3>,tamanho/5,< tamanho/5,0,tamanho*3.5>,0 texture {branco_fosco}}

    object {braco (tamanho,-tamanho/2, 30,ang_braco_esq, ang_antebraco_esq)}
    object {braco (tamanho, tamanho/2,-30,ang_braco_dir, ang_antebraco_dir)}

    object {perna (tamanho, <-1.2*tamanho,0,0>, ang_perna_esq, ang_canela, ang_pe)}
    object {perna (tamanho, < 1.2*tamanho,0,0>, ang_perna_dir, ang_canela, ang_pe)}

    rotate ang_corpo*z
    translate posicao
  }

#end

union
{
  object{ eixos(3.00) }

  object{ chao  translate < 0,0,-15> texture {tx_xadrez}}

  object{ coelho_dancando (clock)}

}