// Last edited on 2003-12-07 12:21:38 by stolfi
#declare N=14; // numero de pares de patas
#declare BASE=5;

// ======================================================================

#declare ctr = < N*BASE/2, 0.00, 0.00 >;
#declare camDir = < -15,60,50 >;

camera {
  location   ctr + 1.40*camDir
  right      -1.00*x
  up         0.75*y
  sky        z
  look_at    ctr
}

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

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

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

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

#declare semente=seed(516235176);

#macro cor(R,G,B)
  texture {
    pigment { color rgb < R,G,B > }
    finish { diffuse 0.5 specular 0.5 roughness 0.03 ambient 0.5 }
  }
#end

#declare cabeca =
  sphere { <-BASE,0,0> BASE cor(0.8,0.6,0.3) }

#macro abdomen(X)
  torus {
    BASE
    BASE/2
    rotate < 0,0,-90 >
    translate < X*BASE,0,0 >
    cor(0.8,0.6,0.3)
  }
#end

#macro fundos(X)
  cone {
    <0,0,0>
    BASE
    <BASE,0,0>
    0
    cor(0.8,0.6,0.3)
    translate < X*BASE-BASE/2,0,0 >
  }
#end

#declare tokenperna = 
  union {
    cylinder { <0,0,-0.3*BASE> <0,0,0.3*BASE> 0.1*BASE cor(0.25,0.25,0.25) }
    cylinder { <0,0,0> <0,BASE,0> 0.1*BASE cor(0.8,0.6,0.3) }
  }

#macro subsubsubperna(d)
  tokenperna
  rotate d*z
#end

#macro subsubperna(c,d)
  union {
    object { tokenperna }
    object {
      subsubsubperna(d)
      translate <0,BASE,0>
    }
    rotate c*z
  }
#end

#macro subperna(b,c,d)
  union {
    object { tokenperna }
    object {
      subsubperna(c,d)
      translate <0,BASE,0>
    }
    rotate b*z
  }
#end

#macro perna(X,a,b,c,d) 
  union {
    object { tokenperna }
    object {
      subperna(b,c,d)
      translate <0,BASE,0>
    }
    rotate a*z
    translate < 0,3*X/2,0 >
  }
#end

#macro ang()
  45-90*rand(semente)
#end

object { cabeca }
#declare i=0;
#while (i<N)
  object { abdomen(i) }
  object { perna(BASE,ang(),ang(),ang(),ang()) translate <i*BASE,0,0> }
  object { perna(BASE,ang(),ang(),ang(),ang()) rotate <180,0,0> translate <i*BASE,0,0> }
  #declare i=i+1;
#end
fundos(N)