// Last edited on 2023-12-25 12:31:09 by stolfi

background{ color rgb < 0.510, 0.430, 0.350 > }

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

#macro dedo(a1_4)
    #local de = cylinder{<0,0,0>, <0.8,0,0>, 0.1}

    union {
        object{de rotate<0, a1_4, 0>}
    }
#end

#macro submembro(a1_3, a1_4)
    #local tronco = cylinder{<0,0,0>, <0,0,-2>, 0.3}

    union {
        object{tronco}
        object{dedo(a1_4) translate <0.2, 0, -2> rotate <0, 0, 0>}
        object{dedo(a1_4) translate <0.2, 0, -2> rotate <0, 0, 120>}
        object{dedo(a1_4) translate <0.2, 0, -2> rotate <0, 0, 240>}
    } 
#end

#macro membro(a1_3, a1_4) 
    #local tronco = cylinder{<0,0,0>, <0,0,-2>, 0.3}

    #local sub = object{submembro(a1_3, a1_4)}

    union {
        object{tronco}
        sphere{<0, 0, -2>, 0.3}
        object{sub rotate<0, -a1_3, 0> translate <0, 0, -2> }
    } 
#end

#macro cabeca()
    union {
        sphere{<0, 0, 0.5>, 0.7}
    }
#end

#macro superior_sub(P3, P4)
    #local pesc = cylinder{<0,0,0>, <0,0, 0.5>, 0.4}
    #local cab = cabeca()

    union {
        object{pesc}
        object{cab rotate <P3, 0, P4> translate<0, 0, 0.5>}
    }
#end

#macro superior(P2, P3, P4) 
    #local c1 = cylinder{<0,0,0>, <0,0, 0.5>, 0.5}
    

    union {
        object{c1}
        sphere{<0, 0, 0.5>, 0.4}
        object{superior_sub(P3, P4) rotate<0, P2, 0> translate<0, 0, 0.5>}
    }
#end

#macro robo(E1_1, E1_2, E1_3, E1_4,
            E2_1, E2_2, E2_3, E2_4,
            D1_1, D1_2, D1_3, D1_4,
            D2_1, D2_2, D2_3, D2_4,
            P1, P2, P3, P4)
    #local corpo = box {
        <-2, -0.5, -2.5>
        <2, 0.5, 2.5>
    } 

    union {
        object{corpo texture{tx_fosca}}
        object{membro(D2_3, D2_4) rotate <0, D2_1, D2_2> translate <-2, 0, -2.5> 
         texture{tx_fosca}}
        object{sphere{<-2, 0, -2.5>, 0.3} texture{tx_fosca}}

        object{membro(E2_3, E2_4) rotate <0, E2_1, E2_2> translate <-2, 0, -2.5> 
         scale <-1, 1, 1> texture{tx_fosca}}
        object{sphere{<2, 0, -2.5>, 0.3} texture{tx_fosca}}

        object{membro(D1_3, D1_4) rotate <0, D1_1, D1_2> translate <-2.3, 0, 2.5> 
         texture{tx_fosca}}
        object{sphere{<-2.3, 0, 2.5>, 0.3} texture{tx_fosca}}

        object{membro(E1_3, E1_4) rotate <0, E1_1, E1_2> translate <-2.3, 0, 2.5> 
         scale <-1, 1, 1> texture{tx_fosca}}
        object{sphere{<2.3, 0, 2.5>, 0.3} texture{tx_fosca}}

        object{superior(-P2, -P3, -P4) rotate <-P1, 0, 0> translate <0, 0, 2.5> texture{tx_fosca}}
    }
#end

#macro cena(tt)
  union {
    #if (tt >= 0 & tt < 0.125)
      robo(tt * 360,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    #end
    #if (tt >= 0.125 & tt < 0.250)
      robo(tt * 360,0, -(tt - 0.125) * 360,0,(tt - 0.125) * 180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    #end
    #if (tt >= 0.250 & tt < 0.375)
      robo(tt * 360,0, -(0.375 - tt) * 360,0,(tt - 0.125) * 180,0,0,0,0,0,0,0,0,0,0,0,0,(tt - 0.250) * 360,0,0)
    #end
    #if (tt >= 0.375 & tt < 0.500)
      robo(135,0,0,(tt - 0.375) * 720,45,0,0,0,0,0,0,0,0,0,0,0,0,45,0,0)
    #end
    #if (tt >= 0.500 & tt < 0.625)
      robo(135,0,0,(0.625 - tt) * 720,45,0,0,0,0,0,0,0,0,0,0,0,0,45,0,0)
    #end
    #if (tt >= 0.625 & tt < 0.750)
      robo((1 - tt) * 360,0,- (tt - 0.625) * 360,0,(0.875 - tt) * 180,0,0,0,0,0,0,0,0,0,0,0,0,(0.750 - tt) * 360,0,0)
    #end
    #if (tt >= 0.750 & tt < 0.875)
      robo((1 - tt) * 360,0,- (0.875 - tt) * 360,0,(0.875 - tt) * 180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    #end
    #if (tt >= 0.875 & tt <= 1)
      robo((1 - tt) * 360,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    #end
  }
#end

#include "eixos.inc"
// object{ eixos(10) }

object{cena(clock)}

#include "camlight.inc"
#declare centro_cena = < 0, 0, 0 >;
#declare raio_cena = 12.0;
#declare dir_camera = < 5, 7, 3 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)