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

#declare tx_plastico = 
  texture{
    pigment{ color rgb < 0.40, 0.70, 1.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

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

#declare tx_espelho = 
  texture{
    pigment{ color rgb < 1.00, 1.00, 1.00 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 1.00, 1.00 > ambient 0.1 }
  }

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.00, 0.00, 0.00 >, color rgb < 1.00, 1.00, 1.0 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#declare r_cilindro = 0.5;
#declare r_bola = 0.6;

#declare toco_hor = 
  cylinder{
    <0, 0, 0>, 
    <0.5, 0, 0>,
    0.1
    texture{ tx_plastico }
  }

#declare toco_ver = 
  cylinder{
    <0, 0, 0>, 
    <0, 0, 0.5>,
    0.1
    texture{ tx_plastico }
  }

#declare tanque1 =
  union {
    cylinder {
      <0, 0, 0>, 
      <0, 0, 4>,
      r_cilindro 
      texture{ tx_plastico }
    }
    sphere {
      <0, 0, 4.3>, r_bola // <x, y, z>, radius
      texture{ tx_plastico }
    }
    object{toco_hor translate<0.5,0,0> rotate <0, 0, 0> }
    object{toco_hor translate<0.5,0,0> rotate <0, 0, 120> }
    object{toco_hor translate<0.5,0,0> rotate <0, 0, 240> }
  }

#declare tanque2 =
  union {
    cylinder {
      <0, 0, 0>, 
      <0, 0, 4>,
      r_cilindro 
      texture{ tx_plastico }
    }
    cone {
      <0, 0, 5.0>, 0.0 // <x, y, z>, center & radius of one end
      <0, 0, 4.0>, 0.5 // <x, y, z>, center & radius of the other end
      texture{ tx_plastico }
    }
    object{toco_hor translate<0.5,0,0> rotate <0, 0, 0> }
    object{toco_hor translate<0.5,0,0> rotate <0, 0, 180> }
    object{toco_ver translate<0,0,5> rotate <0, 0, 0> }
  }
#declare tanque3 = 
  union {
    cylinder {
      <0, 0, 0>, 
      <0, 0, 4>,
      r_cilindro 
      texture{ tx_plastico }
    }
    box {
      <-1, -1, 4>, <1, 1, 5> // <x, y, z> near lower left corner, <x, y, z> far upper right corner
      texture{ tx_plastico }
    }
    object{toco_hor translate<-1,0,4> rotate <0, 0, 90> }
    object{toco_hor translate<1,0,4> rotate <0, 0, 90> }
    object{toco_ver translate<0,0,5> rotate <0, 0, 0> }
  }

#declare roleta = seed(1);

#declare N_MAX = 300;

#declare canos_tanques = array[1000];

#macro gera_tanque1(xx, yy, i, canos_tanques) //coloca tanque na posiçao xx, yy
  #local q1 = <xx+1, yy, 0>;
  #local q2 = <xx+1*(cos(radians(120))), yy+1*(sin(radians(120))),0>;
  #local q3 = <xx+1*(cos(radians(240))), yy+1*(sin(radians(240))),0>;
  #local tq = object{tanque1 translate<xx, yy, 0>}
  #declare canos_tanques[i] = q1;
  #declare canos_tanques[i+1] = q2;
  #declare canos_tanques[i+2] = q3;
tq
#end

#macro gera_tanque2(xx, yy, i, canos_tanques) //coloca tanque na posiçao xx, yy
  #local q1 = <xx-1.5, yy, 4>;
  #local q2 = <xx+1.5, yy, 4>;
  #local q3 = <xx, yy, 5.5>;
  #local tq = object{tanque2 translate<xx, yy, 0>}
  #declare canos_tanques[i] = q1;
  #declare canos_tanques[i+1] = q2;
  #declare canos_tanques[i+2] = q3;
tq
#end

#macro gera_tanque3(xx, yy, i, canos) //coloca tanque na posiçao xx, yy
  #local q1 = <xx+1, yy, 0>;
  #local q2 = <xx-1, yy, 0>;
  #local q3 = <xx, yy, 5.5>;
  #local tq = object{tanque3 translate<xx, yy, 0>}
  #declare canos_tanques[i] = q1;
  #declare canos_tanques[i+1] = q2;
  #declare canos_tanques[i+2] = q3;
tq
#end

#macro gera_tanques(m, n, canos_tanques)
  union{
    #local i = 0;
    #local j = 0;
    #local i_canos = 0;
    #local xx = 0;
    #local yy = 0;
    #while(i < m)
      #while(j < n)
        #local tipo = int(3*rand(roleta)+1);
        #if(tipo = 1)
          #local tq = object{gera_tanque1(xx, yy, i_canos, canos_tanques)}
          object{tq}
          #local i_canos = i_canos+3;
          #local xx = xx + 4;
        #else
        #end
        #if(tipo = 2)
          #local tq = object{gera_tanque2(xx, yy, i_canos, canos_tanques)}
          object{tq}
          #local i_canos = i_canos+3;
          #local xx = xx + 4;
        #else
        #end
        #if(tipo = 3)
          #local tq = object{gera_tanque3(xx, yy, i_canos, canos_tanques)}
          object{tq}
          #local i_canos = i_canos+3;
          #local xx = xx + 4;
        #else
        #end
        #local j = j+1;
      #end
      #local yy = yy+4;
      #local xx = 0;
      #local j = 0;
      #local i = i+1;
    #end
  }
#end

#include "eixos.inc"

//cena

#local nfilas = 5;
#local ncols = 3;

union{
  // object{ eixos(3.00) }
  object{gera_tanques(nfilas,ncols, canos_tanques)}
  //object{criar_tubulacao(nfilas, ncols, canos_tanques)};
}

#declare tam_cena = < 4*ncols, 4*nfilas, 6 >;

#include "camlight.inc"
#declare centro_cena = 0.5*tam_cena;
#declare raio_cena = 0.55*vlength(tam_cena);
#declare dir_camera = < 300.00, 300.00, 200.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)