// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2023-09-25 17:45:24 by stolfilocal

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

background{ color rgb < 0.5, 0.5, 0.5 > }

#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_fosca = 
  texture{
    pigment{ color rgb < 1.00, 0.00, 0.00 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

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

#declare tx_vidro = 
  texture{
    pigment{ color rgb < 0.85, 0.95, 1.00 > filter 0.70 }
    finish{ diffuse 0.03 reflection 0.25 ambient 0.02 specular 0.25 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 }
    scale 2.0
  }

// ======================================================================
#declare s = seed(1);
#declare A = array[1000];
#declare total = 0;

#macro torre1(cx,cy)
  union {
  object {intersection {
    cone{ <0,0,0>,0.5
    <0,0,1>,0 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 0.00 > }}
    box{ <-0.25,-0.25,0>, <0.25,0.25,1> texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 0.00 >}}
    
  } translate <cx,cy,0>}
    cylinder {<0,0.25,0.5>, <0,0.3,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<0,-0.25,0.5>, <0,-0.3,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<0.25,0,0.5>, <0.3,0,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<-0.25,0,0.5>, <-0.3,0,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
  }
  #declare A[total] = <cx, cy+0.3,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx, cy-0.3,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx+0.3, cy,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx-0.3, cy,0.5>;
  #declare total = total + 1;

#end

#macro torre2(cx,cy)
  union {
    cylinder { <0,0,0>, <0,0,0.5>, 0.25 texture {tx_plastico} pigment { color rgb < 1.00, 0.00, 0.00 > } translate <cx,cy,0>}
    cone{
      <0,0,0.5>, 0.25 <0,0,1>, 0 texture {tx_plastico} pigment { color rgb < 1.00, 0.00, 0.00 >}  translate <cx,cy,0>}
    cylinder {<0,0.25,0.5>, <0,0.3,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<0,-0.25,0.5>, <0,-0.3,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<0.25,0,0.5>, <0.3,0,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<-0.25,0,0.5>, <-0.3,0,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
  }
  #declare A[total] = <cx, cy+0.3,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx, cy-0.3,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx+0.3, cy,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx-0.3, cy,0.5>;
  #declare total = total + 1;
#end

#macro torre3(cx,cy)
  union {
    box{ <-0.25,-0.25,0>, <0.25,0.25,0.5> texture {tx_plastico} pigment { color rgb < 0.00, 0.00, 1.00 >} translate <cx,cy,0>}
    cylinder { <0,0,0.5>, <0,0, 1>, 0.25 texture {tx_plastico} pigment { color rgb < 0.00, 0.00, 1.00 > } translate <cx,cy,0>}

    cylinder {<0,0.25,0.5>, <0,0.3,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<0,-0.25,0.5>, <0,-0.3,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<0.25,0,0.5>, <0.3,0,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
    cylinder {<-0.25,0,0.5>, <-0.3,0,0.5> 0.05 texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > } translate <cx,cy,0>}
  }
  #declare A[total] = <cx, cy+0.3,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx, cy-0.3,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx+0.3, cy,0.5>;
  #declare total = total + 1;
  #declare A[total] = <cx-0.3, cy,0.5>;
  #declare total = total + 1;
#end

#macro torre_r(rr,i,j)
  #if (rr<1)
    object{torre1(i,j)}
  #else
    #if (rr<2)
      object{torre2(i,j)}
    #else
      object{torre3(i,j)}
    #end
  #end
#end
  

#declare rtubo = 0.05;

#macro tubulacao(x1,y1,x2,y2)
  object {
    #local altura = 5.0*rand(s);
    union {
      cylinder {<x1, y1, 0.5>, <x1, y1, 0.5+altura>, rtubo texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > }}
      cylinder {<x1, y1, 0.5+altura>, <x2, y2, 0.5+altura>, rtubo texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > }}
      cylinder {<x2, y2, 0.5>, <x2, y2, 0.5+altura>, rtubo texture {tx_plastico} pigment { color rgb < 1.00, 1.00, 1.00 > }}
      
      
    }
  }

#end

#macro grid(m,n)
  #for(i, 0, m)
    #for(j, 0, n)
      #local r = 3.0*rand(s);
      object{torre_r(r,i,j) }
    #end
  #end
  #while (total > 1)
    #local ponto1 = total*rand(s);
    #local start = A[ponto1];
    #declare A[ponto1] = A[total-1];
    #declare total = total-1;

    #local ponto2 = total*rand(s);
    #local fini = A[ponto2];
    #declare A[ponto2] = A[total-1];
    #declare total = total-1;

    object{tubulacao(start.x,start.y, fini.x, fini.y)}
  #end
#end

#include "eixos.inc"

#declare nfilas = 7;
#declare ncols = 4;

grid(nfilas, ncols)

object{ torre_r(0.50,2,ncols+2) }
object{ torre_r(1.50,4,ncols+2) }
object{ torre_r(2.50,6,ncols+2) }


#declare tam_cena = < nfilas+2, ncols+3, 5 >;


#include "camlight.inc"
#declare centro_cena = 0.5*tam_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)