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

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

#declare tanque_base_cilindro =
    cylinder {
        <0, 0, -1>, <0, 0, 1>, 0.5 // center of one end, center of other end, radius
        open // remove end caps
        texture {tx_plastico}
    }

#declare tanque_topo_esfera =
    sphere {
        <0, 0, 1.5>, 0.5 // <x, y, z>, radius
        texture {tx_plastico}
    }

#declare cano_horizontal_y =
    cylinder {
        <0, 0, 0>, <0, 0.5, 0>, 0.1 // center of one end, center of other end, radius
        open // remove end caps
        texture {tx_plastico}
    }

#declare cano_vertical =
    cylinder {
        <0, 0, 0>, <0, 0, 0.5>, 0.1 // center of one end, center of other end, radius
        open // remove end caps
        texture {tx_plastico}
    }

#declare tanque1 =
    union {
        object {tanque_base_cilindro}
        object {tanque_topo_esfera}
        object {cano_horizontal_y translate <0, 0.5, 0>} // <x, y, z>
        object {cano_horizontal_y translate <0, -1, 0>}
        object {cano_vertical translate <0, 0, 2>} // <x, y, z>}
    }

#declare tanque_base_quadrado =
    box {
        <-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5> // <x, y, z> near lower left corner, <x, y, z> far upper right corner
        texture {tx_plastico}
    }

#declare tanque_topo_cone =
    cone {
        <0, 0, 0.5>, 0.4 // <x, y, z>, center & radius of one end
        <0, 0, 1>, 0.2 // <x, y, z>, center & radius of the other end
        texture {tx_plastico}
    }

#declare cano_horizontal_x =
    cylinder {
        <0, 0, 0>, <0.5, 0, 0>, 0.1 // center of one end, center of other end, radius
        open // remove end caps
        texture {tx_plastico}
    }

#declare tanque2 =
    union {
        object {tanque_base_quadrado}
        object {tanque_topo_cone}
        object {cano_horizontal_y translate <0, 0.2, 0.8>}
        object {cano_horizontal_y translate <0, -0.7, 0.8>}
        object {cano_horizontal_x translate <0.5, 0, 0>}
    }

#declare tanque3 =
    union {
        object {tanque_base_cilindro}
        object {tanque_topo_cone translate <0, 0, 0.5>}
        object {cano_vertical translate <0, 0, 1.5>}
        object {cano_horizontal_y translate <0, 0.5, 0>}
        object {cano_horizontal_y translate <0, -1, 0>}
    }

#declare arr = array[1000]
#declare N = 0;

#macro gera_tanques(m, n)
    #declare roleta1 = seed(m * n + 1234);

    #local pos_x = - m / 2;
    #local loop_m = 0;
    #while (loop_m < m)
        #local pos_y = - n / 2;
        #local loop_n = 0;
        #while (loop_n < n)
            #local rand_n = 3 * rand(roleta1);
            #switch (rand_n)
                #range (0, 1)
                    #local q1 = <pos_x, pos_y + 0.5, 0>;
                    #local q2 = <pos_x, pos_y - 1, 0>;
                    #local q3 = <pos_x, pos_y, 2>;
                    #declare arr[N] = q1;
                    #declare arr[N + 1] = q2;
                    #declare arr[N + 2] = q3;
                    #declare N = N + 3;
                    union {
                        object {tanque1 translate <pos_x, pos_y, 0>}   
                    }
                #break
                #range (1, 2)
                    #local q1 = <pos_x, pos_y + 0.2, 0.8>;
                    #local q2 = <pos_x, pos_y - 0.7, 0.8>;
                    #local q3 = <pos_x + 0.5, pos_y, 0>;
                    #declare arr[N] = q1;
                    #declare arr[N + 1] = q2;
                    #declare arr[N + 2] = q3;
                    #declare N = N + 3;
                    union {
                        object {tanque2 translate <pos_x, pos_y, 0>}
                    }
                #break
                #range (2, 3)
                    #local q1 = <pos_x, pos_y, 1.5>;
                    #local q2 = <pos_x, pos_y + 0.5, 0>;
                    #local q3 = <pos_x, pos_y - 1, 0>;
                    #declare arr[N] = q1;
                    #declare arr[N + 1] = q2;
                    #declare arr[N + 2] = q3;
                    #declare N = N + 3;
                    union {
                        object {tanque3 translate <pos_x, pos_y, 0>}
                    }
                #break
            #end
            #local loop_n = loop_n + 1;
            #local pos_y = pos_y + 3;
        #end
        #local pos_x = pos_x + 3;
        #local loop_m = loop_m + 1;
    #end
#end

gera_tanques(4, 2)

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 10.0;
#declare dir_camera = < 14.00, 7.00, 4.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)