//Rafael Henrique Castanheira de Souza, ra017134
//laboratorio : IC - 4

// ======================================================================
// CÂMERA 

camera {
  location  < 50.00, 30.00, 40.00 >       // Posição do observador.
  right     -0.70*x              	  // Largura RELATIVA da imagem.
  up        1.00*y                 	  // Altura RELATIVA da imagem.      
  sky       z                             // Qual direção é "para cima"?
  look_at   <  0.00, 0.00, 0.00 >         // Para onde a câmera está apontando.
} 
// Nota: os parâmetros "right" e "up" devem ter a mesma proporção
// que os parâmetros ${WIDTH} e ${HEIGHT} no Makefile.

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

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

light_source {
  10 * < -50.0, -40.0, +10.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

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

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


#declare cinza_claro = < 0.70, 0.70, 0.70 >;
#declare cinza_transparente = 
  texture {
    finish { diffuse 0.1 specular 1.0 roughness 0.001 ambient 0.1 reflection 0.20}
    pigment { color cinza_claro filter 1 }	
  }


#declare preto = 
  texture {
    pigment { color rgb < 0.00, 0.00, 0.00 > }
    finish { diffuse 0.8 specular 0.9 roughness 0.015 ambient 0.4 }
  }


#declare verde_folha = 
texture {
    pigment { color rgb < 0.20, 0.80, 0.20 > }
    finish { diffuse 0.5 specular 0.0 roughness 0.05 ambient 0.1 }
  }	

#declare marrom_casca = 
texture {
    pigment { color rgb < 0.7, 0.70, 0.00 > }
    finish { diffuse 0.5 specular 0.0 roughness 0.5 ambient 0.1 }
  }

#declare branco = 
texture {
    pigment { color rgb < 1.0, 1.00, 1.00 > }
    finish { diffuse 0.5 specular 0.4 roughness 0.005 ambient 0.1 }
  }

#declare cinza_predio = 
texture {
    pigment { color rgb < 0.7, 0.70, 0.70 > }
    finish { diffuse 0.5 specular 0.4 roughness 0.5 ambient 0.1 }
  }

#declare amarelo = 
texture {
    pigment { color rgb < 1.0,1.00, 0.00 > }
    finish { diffuse 0.4 specular 0.8 roughness 0.005 ambient 0.1 }
  }


declare fundo =
  plane{<0,0,1>, -1
    texture{       
      pigment {checker <0.00, 0.80, 0.00>,<0.00, 1.00,0.00> }
      finish  {ambient 0.1 diffuse 0.9 }
      scale 0.5
  }
}

#declare arvore = 
  union{
    sphere {<0, 0, 2.65>, 0.80
        texture {verde_folha}
    }
    sphere {<-0.5, 0, 2.65>, 0.6
        texture {verde_folha}
    }
    sphere {<0.5, 0, 2.65>, 0.6
        texture {verde_folha}
    }
    cylinder {
    <0.00, 0.00, 0.30>,
    <0.00, 0.00, 2.00>,
    0.35
    texture {marrom_casca}	
  }
  cone {
    <0, 0, 0.30>, 0.35    // Center and radius of one end
    <0, 0, 0.00>, 0.65    // Center and radius of other end
  texture { marrom_casca }
  }
 }


#declare janela_fechada = 
  union {  	
    box {
    < 0.10, -0.5, 0.00>,
    <-0.10,  0.5,	 1.50>
    texture {marrom_casca} 	
    }
    box {
    <0.10 ,  0.05, 0.00>,
    <-0.10, -0.05, 1.50>
    texture {branco}
    }
    translate < 0 ,0,0>
}

#declare janela_aberta = 
  union {  	
    box {
    < 0.10, -0.5, 0.00>,
    <-0.10,  0.5, 1.50>
    texture {amarelo} 	
    }
    box {
    <0.20 ,  0.5, 0.00>,
    <0.00,   0.75, 1.50>
    texture {marrom_casca}
    }
    box {
    <0.20 ,  -0.5, 0.00>,
    <0.00,  -0.75, 1.50>
    texture {marrom_casca}
    }
    translate < 0 ,0,0>
}

#declare predio =
  difference{
  union{
    box {
    < 10.00, 10.00,  0.00>,
    <-10.00, -10.00, 24.00>
    texture {cinza_predio}
    }
    box {
    < 10.01, -2.50,  0.00>,
    < 15.00,  2.50, 0.50>
    texture {cinza_predio}
    }
  }
  box {
    < 6.00, -2.50,  0.1>,
    <10.01, 2.50, 3.60>
    texture {branco}
    }
  box {
    < 9.00,  9.00, 22.5>,
    <-9.00, -9.00, 30.00>
    texture {branco}
    }
}

#declare gerador = seed (12324343577);



union {

union{
  #declare i = 0;
  #while (i < 100)
     //desenhando os bosques
     object {arvore rotate 45*z*rand(gerador)
             translate <  20*rand(gerador),15 + 10*rand(gerador),0 > }
     
     #declare i = i + 1;
  #end
  }
  union{
  #declare i = 0;
  #while (i < 100)
     object {arvore rotate 45*z*rand(gerador)
             translate <  20*rand(gerador),-15 - 10*rand(gerador),0 > }
     
     #declare i = i + 1;
  #end
  }
  

  
  object {janela_aberta}
  object {predio}
  
  
  #declare lin = 1;
  

//desenhando as janelas, linha a linha, coluna a coluna e face a face no predio  
#while (lin < 6)
  #declare col = 1;  
    #while (col < 6)
      #if ( rand(gerador) > 0.5)
        //desenhando a janela nas 4 faces do edificio
        object {janela_fechada translate<10,-13.50 + col*4 + 1.5,1.25+ lin*4>}
        object {janela_fechada translate<10,-13.50 + col*4 + 1.5,1.25+ lin*4> rotate 90*z}
        object {janela_fechada translate<10,-13.50 + col*4 + 1.5,1.25+ lin*4> rotate 180*z}
        object {janela_fechada translate<10,-13.50 + col*4 + 1.5,1.25+ lin*4> rotate 360*z}  
      #else
        //desenhando a janela nas 4 faces do edificio
        object {janela_aberta translate<10,-13.00 + col*4 + 1, 1.25+ lin*4>            }
        object {janela_aberta translate<10,-13.00 + col*4 + 1, 1.25+ lin*4> rotate 90*z}
        object {janela_aberta translate<10,-13.00 + col*4 + 1, 1.25+ lin*4> rotate 180*z}
        object {janela_aberta translate<10,-13.00 + col*4 + 1, 1.25+ lin*4> rotate 360*z}

      #end


    #declare col = col + 1; 
    #end
    
    #declare lin = lin + 1;
  #end
  object {fundo}
  	
}