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

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

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

#declare tx_fosca =
  texture{
    pigment{ color rgb < 0.84, 0.84, 0.84 > }
    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
  }

#declare chao =
  box{ <-20,-20,-1>, <+20,+20,0> }

#include "eixos.inc"

#declare NQ = 6;

#macro antebraco()

        cylinder{ < 0, 0, 0 >, < 0, 1, 0 >, 0.3 texture{ tx_fosca } }

#end

#macro braco(ang1)
        union { cylinder{ < 0, 0, 0 >, < 0, 1, 0 >, 0.3 texture{ tx_fosca } }
                object { antebraco() rotate x*ang1 translate 1*y } }
#end

#macro pe()

        cylinder{ < 0, 0, 0 >, < 1.5, 0, 0 >, 0.5 texture{ tx_preto } }

#end

#macro pernabaixo(ang1)
        union { cylinder{ < 0, 0, -2.00 >, < 0, 0, 0 >, 0.5 texture{ tx_fosca } }
                object { pe() rotate y*ang1 translate -2*z } }
#end

#macro pernacima(ang1, ang2)
        union { cylinder{ < 0, 0, -2 >, < 0, 0, 0 >, 0.5 texture{ tx_fosca } }
                object { pernabaixo(ang1) rotate y*ang2 translate -2*z } }
#end

#macro corpo()

union { sphere{ < 0,0,0 >, 0.60 texture{ tx_fosca } }
        cone { <0, -0.2, 0.5>, 0.2, <0, -0.2, 1.2>, 0  texture{ tx_fosca } }
        cone { <0, 0.2, 0.5>, 0.2, <0, 0.2, 1.2>, 0  texture{ tx_fosca } }
        cone { <0, 0, -0.6>, 0.2, <0, 0, -2.5>, 0.7  texture{ tx_fosca } }
 }
#end

#declare tempo = array[NQ]
#declare tempo[0] = 0;
#declare tempo[1] = 0.1;
#declare tempo[2] = 0.3;
#declare tempo[3] = 0.5;
#declare tempo[4] = 0.7;
#declare tempo[5] = 1;

#declare ang_1 = array[NQ];

#declare ang_1[0] =0;
#declare ang_1[1] =25;
#declare ang_1[2] =35;
#declare ang_1[3] =60;
#declare ang_1[4] =-10;
#declare ang_1[5] =-5;

#declare ang_2 = array[NQ];

#declare ang_2[0] =0;
#declare ang_2[1] =10;
#declare ang_2[2] =-35;
#declare ang_2[3] =-20;
#declare ang_2[4] =40;
#declare ang_2[5] =15;

#declare ang_3 = array[NQ];

#declare ang_3[0] =0;
#declare ang_3[1] =45;
#declare ang_3[2] =50;
#declare ang_3[3] =-20;
#declare ang_3[4] =-10;
#declare ang_3[5] =0;

#macro coelho(ang_1, ang_2, ang_3)

union { object { corpo () scale <2,2,2 > translate 5*z}
        object { pernacima (ang_1, ang_2) rotate y*ang_3 translate -0.7*y }
        object { pernacima (ang_1, ang_2) rotate y*40 translate 0.7*y}
        object { braco (ang_1) rotate y*ang_2 scale -1*y translate -0.5*y translate 2*z}
        object { braco (ang_1) rotate y*ang_2 translate 0.5*y translate 2*z}
 }
#end

#macro quadro_anterior(fase)
        #local k = 0;

        #while((k<NQ-1) & (tempo[k+1]<fase))
                #local k = k+1;
        #end
        k
#end

#macro coelho_mexendo(ang_11,ang_22,ang_33)
union{
        #local temp1 = pi*2*(ang_11/360);
        #local temp2 = pi*2*(ang_22/360);
        #local temp3 = pi*2*(ang_33/360);
        #local d = ((1-abs(cos(temp1)))*3+(1-abs(cos(temp1+temp2)))*3+sin(temp3+temp1+temp2)*1.5);
        object{ coelho(ang_11,ang_22,ang_33) translate <0,0,-d>}
}
#end

#macro interpol(ii,kk,jj,ll,mm)
        #local tt = (mm-ii)/(jj-ii);
        ((1-tt)*kk+tt*ll);
#end

#macro coelho_dancando(fase)

#declare tempo0 = 0;
#declare tempo1 = 0.3;
#declare tempo2 = 0.5;
#declare tempo3 = 0.7;
#declare tempo4 = 0.9;
#declare tempo5 = 1;

#if ((fase >= tempo0) & (fase <= tempo1))

        #declare ang_1 = interpol(tempo0,ang_1[0],tempo1,ang_1[1],fase);

        #declare ang_2 = interpol(tempo0,ang_2[0],tempo1,ang_2[1],fase);

       #declare ang_3 = interpol(tempo0,ang_3[0],tempo1,ang_3[1],fase);
#end

#if ((fase > tempo1) & (fase <= tempo2))

        #declare ang_1 = interpol(tempo1,ang_1[0],tempo2,ang_1[1],fase);

        #declare ang_2 = interpol(tempo1,ang_2[0],tempo2,ang_2[1],fase);

       #declare ang_3 = interpol(tempo1,ang_3[0],tempo2,ang_3[1],fase);

 #end

#if ((fase > tempo2) & (fase <= tempo3))

#declare ang_1 = interpol(tempo2,ang_1[0],tempo3,ang_1[1],fase);

#declare ang_2 = interpol(tempo2,ang_2[0],tempo3,ang_2[1],fase);

#declare ang_3 = interpol(tempo2,ang_3[0],tempo3,ang_3[1],fase);

 #end

#if ((fase > tempo3) & (fase < tempo4))

#declare ang_1 = interpol(tempo3,ang_1[0],tempo4,ang_1[1],fase);

#declare ang_2 = interpol(tempo3,ang_2[0],tempo4,ang_2[1],fase);

    #declare ang_3 = interpol(tempo3,ang_3[0],tempo4,ang_3[1],fase);

      #end

#if ((fase > tempo4) & (fase < tempo5))

#declare ang_1 = interpol(tempo4,ang_1[0],tempo5,ang_1[1],fase);

#declare ang_2 = interpol(tempo4,ang_2[0],tempo5,ang_2[1],fase);

#declare ang_3 = interpol(tempo4,ang_3[0],tempo5,ang_3[1],fase);

#end

object { coelho_mexendo(ang_1,ang_2,ang_3) }

#end

object { coelho_dancando(clock) }

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 11.0;
#declare dir_camera = < 20, 0, 5 >;
#declare dist_camera = 15.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)