// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2023-09-25 18:44:37 by stolfilocal

// ======================================================================
// CORES E TEXTURAS

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

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

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }
// ======================================================================

#declare raio = 2.000;

// Partes da cena:

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

#macro tanque_1(pos_x, pos_y)
    #local p1 = <1.8, 0, 1>;
    #local p2 = <-1.8, 0, 1>;
    #local p3 = <0, 1.8, 2>;
    #local p4 = <0, -1.8, 2>;

    #local tanque = union {
        cylinder {
            <0, 0, 0>,     // Center of one end
            <0, 0, 3>,     // Center of other end
            1            // Radius
        }
        cone {
            <0, 0, 3>, 1    // Center of other end
            <0,0,4>, 0.3
        }

        cylinder {
            <0, 0, 1>,     // Center of one end
            p1,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1>,     // Center of one end
            p2,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 2>,     // Center of one end
            p3,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 2>,     // Center of one end
            p4,     // Center of other end
            0.2            // Radius
        }

        texture { tx_plastico }
    }

    #declare TUBOS[N] = p1 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p2 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p3 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p4 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    object { tanque translate<pos_x, pos_y, 0> }
#end

#macro tanque_2(pos_x, pos_y)
    #local p1 = <1.4, 0, 1.5>;
    #local p2 = <-1.4, 0, 1.5>;
    #local p3 = <0, 1.4, 1.5>;
    #local p4 = <0, -1.4, 1.5>;

    #local tanque = union {
        cone {
            <0, 0, 0>, 0.3    // Center of other end
            <0,0,1>, 1
        }
        cylinder {
            <0, 0, 1>,     // Center of one end
            <0, 0, 2>,     // Center of other end
            1            // Radius
        }
        sphere { 
            < 0,0,2 >, 1
        }

        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p1,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p2,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p3,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p4,     // Center of other end
            0.2            // Radius
        }

        texture { tx_plastico }
    }

    #declare TUBOS[N] = p1 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p2 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p3 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p4 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    object { tanque translate<pos_x, pos_y, 0> }
#end

#macro tanque_3(pos_x, pos_y)
    #local p1 = <1.4, 0, 1.5>;
    #local p2 = <-1.4, 0, 1.5>;
    #local p3 = <0, 1.4, 1.5>;
    #local p4 = <0, -1.4, 1.5>;

    #local tanque = union {
        cone {
            <0, 0, 0>, 1.4    // Center of other end
            <0,0,1.2>, 0.6
        }
        cylinder {
            <0, 0, 1.2>,     // Center of one end
            <0, 0, 3>,     // Center of other end
            0.6        // Radius
        }
        cone {
            <0, 0, 3>, 0.6    // Center of other end
            <0,0,4>, 1.4
        }

        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p1,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p2,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p3,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <0, 0, 1.5>,     // Center of one end
            p4,     // Center of other end
            0.2            // Radius
        }

        texture { tx_plastico }
    }

    #declare TUBOS[N] = p1 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p2 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p3 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;

    #declare TUBOS[N] = p4 + <pos_x, pos_y, 0>; 
    #declare N = N + 1;


    object { tanque translate<pos_x, pos_y, 0> }
#end

#declare roleta = seed(31415);

#macro gera_tanques(m,n)
    union {
        #for (XCount,0,m-1)
            #for (YCount,0,n-1)
                #local k = int(3*rand(roleta));
                #if (k = 0)
                    tanque_1(5*XCount, 5*YCount)
                #end
                #if (k = 1)
                    tanque_2(5*XCount, 5*YCount)
                #end
                #if (k = 2)
                    tanque_3(5*XCount, 5*YCount)
                #end
            #end
        #end
    }
#end

#macro tubulacao(p, q)
    #local altura = 3 + int(8*rand(roleta));

    union {
        cylinder {
            p,     // Center of one end
            <p.x, p.y, altura>,     // Center of other end
            0.2            // Radius
        }    
        cylinder {
            <p.x, p.y, altura>,     // Center of other end
            <q.x, q.y, altura>,     // Center of other end
            0.2            // Radius
        }
        cylinder {
            <q.x, q.y, altura>,     // Center of other end
            q,     // Center of one end
            0.2            // Radius
        }  
        texture { tx_plastico }
    }
#end

#macro gera_tubulacoes()
    union {
        #while (N > 0)
            #local i = int(N*rand(roleta));
            #local j = int((N-1)*rand(roleta));
            #if (j >= i)
                #local j = j + 1;
            #end

            tubulacao(TUBOS[i], TUBOS[j])

            #declare TUBOS[i] = TUBOS[N-1];
            #declare N = N - 1;

            #declare TUBOS[j] = TUBOS[N-1];
            #declare N = N - 1;
        #end
    }
#end

#include "eixos.inc"

#declare nfilas = 7;
#declare ncols = 5;

#declare mrg = 2.4999;

#declare min_cena = < 5*(0-0.5), 5*(0-0.5), -1 >;
#declare max_cena = < 5*(nfilas-0.5), 5*(ncols-0.5), 11 >;

#declare chao = box{ <min_cena.x-mrg, min_cena.y-mrg, -1>, <max_cena.x+mrg, max_cena.y+mrg, 0> }

union{
  // object{ eixos(3.00) }
  object{ gera_tanques(nfilas, ncols) }
  object{ gera_tubulacoes() }
  object{ chao  translate < 0,0,-0.1 > texture{ tx_xadrez scale 5 } }
}
#declare tam_cena = max_cena - min_cena;

#include "camlight.inc"
#declare centro_cena = 0.5*(min_cena+max_cena);
#declare raio_cena = 0.55*vlength(tam_cena);
#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)