// Last edited on 2004-01-22 23:57:08 by stolfi
// ======================================================================

#declare ctr = < 20.00, 20.00, 0.00 >;
#declare camDir = < 0.00, 0.00, 70.00 >;

camera {
  location   ctr + 1.00*camDir
  right      -1.00*x
  up         0.75*y
  sky        < sin(0.25*pi*clock/2), cos(0.25*pi*clock/2), 0 >
  look_at    ctr
}

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

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

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

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

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

#declare semente=seed(2345134);

background{ color rgb < 0.25, 0.20, 0.25 > }

#declare cinza =
  texture {
    pigment { color rgb < 0.75, 0.75, 0.75 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.03 ambient 0.5 }
  }

#declare azul =
  texture {
    pigment { color rgb < 0.00, 0.00, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.03 ambient 0.5 }
  }

#declare verde =
  texture {
    pigment { color rgb < 0.00, 1.00, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.03 ambient 0.5 }
  }

#declare vermelho = 
  texture {
    pigment { color rgb < 1.00, 0.00, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.03 ambient 0.5 }
  }

#macro cor_aleatoria()
  pigment { color rgb <rand(semente),rand(semente),rand(semente)> }
  finish { diffuse 0.5 specular 0.5 roughness 0.03 ambient 0.5 }
#end

#declare nodo =
  sphere {
    <0, 0, 0>
    1.0
    texture { vermelho }
  }

#declare enlaceX =
  cylinder {
    <0, 0, 0>
    <10, 0, 0>
    0.3
    texture { cinza }
  }

#declare enlaceY =
  cylinder {
    <0, 0, 0>
    <0, 10, 0>
    0.3
    texture { cinza }
  }

#macro pacote()
  #if (rand(semente)<=0.5)
    cylinder { <-2, 0, 0> <2, 0, 0> 1 }
  #else
    box { <-1, -1, -1> <1, 1, 1> }
  #end
#end

#macro posicao()
  #if (rand(semente)<=0.5)
    #declare mult=1;
  #else
    #declare mult=-1;
  #end

  #if (rand(semente)<=0.5)
    translate < 20-20*mult+10*mult*clock, 10*int(4*rand(semente)), 0 >
  #else
    rotate 90*z
    translate < 10*int(4*rand(semente)), 20-20*mult+10*mult*clock, 0 >
  #end
#end

#declare Count1 = 0;
#while (Count1 < 4)
  #declare Count2=0;
  #while (Count2 < 5)
    object { nodo translate <10*Count2,10*Count1,0> }
    object { enlaceY translate <10*Count2,10*Count1,0> }
    #if (Count2 > 0)
      object { enlaceX translate <10*(Count2-1),10*Count1,0> }
    #end
    #declare Count2=Count2+1;
  #end
  #declare Count1=Count1+1;
#end
#declare Count2 = 0;
#while (Count2 < 5)
  object { nodo translate <10*Count2,10*Count1,0> }
  #if (Count2 > 0)
    object { enlaceX translate <10*(Count2-1),10*Count1,0> }
  #end
  #declare Count2=Count2+1;
#end

#declare Count3 = 0;
#while (Count3 < 10)
object { 
  pacote()
  texture {cor_aleatoria()}
  posicao()
}
#declare Count3=Count3+1;
#end