// Priscilla Sanches Marques
// RA : 981944
// MC 930 - Computacao Grafica
// 2 semestre 2000
// Laboratorio 7
// Prof. Stolfi 

#include "colors.inc"
#include "textures.inc"

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

light_source {
  < 50.00, 7.00, -20.00 >
  color rgb < 1.00, 1.00, 1.00 >
}

camera {
  location  < 36.00, 10.00, 40.00 >
  //sky <>
  look_at   < 0.00, 2.00, 1.00 >
} 

// Planos de fundo
plane { y, 500
  texture {
  pigment { SkyBlue }
    finish { ambient 1 diffuse 0}
  }
  texture {
    pigment {
      bozo
      turbulence .5
      color_map {
        [0 White]
        [1 White filter 1]
       }
     }
     finish { ambient 1 diffuse 0 }
     scale <1000, 250, 250>
     rotate <5, 45, 0>
  }
} 

plane { y,-12
  texture {
  pigment { LimeGreen }
    finish { ambient 1 diffuse 0}
  }
  texture {
    pigment {
      bozo
      turbulence .5
      color_map {
        [0 White]
        [1 White filter 1]
       }
     }
     finish { ambient 1 diffuse 0 }
     scale 10
    translate  50*x
  }
} 
 

// Predio :
#declare estrutura_predio = 
box {
  <0, 0, 0>,
  <12,18,4>   
  texture { 
    Brushed_Aluminum  
    finish {
      ambient .1
      diffuse .4
      specular 1
      roughness 0.001
      reflection .5
      metallic
    }
  }
}

#declare porta =
box {
  <4, 0, 0>,
  <8, 4, 1>   
  texture { 
    Bright_Bronze  
    finish {
      ambient .1
      diffuse .4
      specular 1
      roughness 0.001
      reflection .5
      metallic
    }
  }
}

#declare janela_quadrada_esquerda =
box {
  <2, 7, -0.2>,
  <4, 9, 1>   
  texture { 
    Bright_Bronze  
    finish {
      ambient .1
      diffuse .4
      specular 1
      roughness 0.001
      reflection .5
      metallic
    }
  }
}

#declare janela_quadrada_direita =
box {
  <8, 7, -0.2>,
  <10, 9, 1>   
  texture { 
    Bright_Bronze  
    finish {
      ambient .1
      diffuse .4
      specular 1
      roughness 0.001
      reflection .5
      metallic
    }
  }
}

#declare janela_redonda_terreo =
sphere {
  < 11.3, 3.00, 2.00 >, 1.00  
  texture {
    Dark_Green_Glass
    normal { 
      bumps 0.4 
      scale 0.2 
    }
    finish { 
      phong 1
      reflection 0.75
    }
  }  
}

#declare janela_redonda_lateral =
sphere {
  < 11.3, 8.00, 2.00 >, 1.00  
  texture {
    Dark_Green_Glass
    normal { 
      bumps 0.4 
      scale 0.2 
    }
    finish { 
      phong 1
      reflection 0.75
    }
  }  
}

#declare andar_terreo =
union {
 object { estrutura_predio }
 object { porta }
 object { janela_redonda_terreo }
}

#declare andar = 
union {
  object { janela_quadrada_esquerda }
  object { janela_quadrada_direita }
  object { janela_redonda_lateral } 
}

#declare i = 0;
#declare predio =
merge{
  object { andar_terreo }
  #while (i < 3 )
       object { andar translate <0.0, i*4.0, 0.0> }
    #declare i = i+1;
  #end
}

// Planta da cidade :
#declare rua1 =
box {
  <36, 0, 0>,
  <48, 0.1, 24>   
  texture { pigment { Black } }
}

#declare rua2 =
box {
  <60, 0, 6>,
  <72, 0.1, 24>   
  texture { pigment { Black } }
}

#declare rua3 = 
box {
  <72, 0, 6>
  <84, 0.1, 18>
  texture { pigment { Black } }
}

#declare rua4 =
box {
  <84, 0, 6>
  <96, 0.1, 24>
  texture { pigment { Black } }
}

#declare rua_principal1 =
box {
  <0, 0, 24>
  <120, 0.1, 48>
  texture { pigment { Black } }
}

#declare rua5 =
box {
  <24, 0, 48>
  <36, 0.1, 96>
  texture { pigment { Black } }
}

#declare rua6 =
box {
  <84, 0, 48>
  <96, 0.1, 60>
  texture { pigment { Black } }
}

#declare rua7 =
box {
  <102, 0, 72>
  <114, 0.1, 96>
  texture { pigment { Black } }
}

#declare rua8 =
box {
  <66, 0, 72>
  <78, 0.1, 96>
  texture { pigment { Black } }
}

#declare rua9 =
box {
  <78, 0, 60>
  <90, 0.1, 78>
  texture { pigment { Black } }
}

#declare rua_principal2 =
box {
  <0, 0, 96>
  <120, 0.1, 120>
  texture { pigment { Black } }
}

#declare plano_cidade =
union {
  object { rua1 }
  object { rua2 }
  object { rua3 }
  object { rua4 }
  object { rua5 }
  object { rua6 }
  object { rua7 }
  object { rua8 }
  object { rua9 }
  object { rua_principal1 }
  object { rua_principal2 }
}

// A construcao final da cena :
#declare i = 0;
#declare g = seed(pi);

// Infelizmente o Loop ficou infinito e a versao ficou sem o
// desenho randomico mesmo ... :-(

union {
  object { plano_cidade  scale <0.25, 0.25, 0.25> }
  //#while (i < 4) 
    //#declare r = ((rand(g)*3)+1);
    
    //#if (r = 1) // rua a ser inserido o predio = 1
      //#declare i = i+1;
      //#declare gg = seed(pi);
      //#declare rr = ((rand(gg)*1)+1);
      //#if (rr = 1) // posiciona na 1 parte do quarteirao
        object { predio translate <24.0, 0.0, 0.0> scale <0.25, 0.25, 0.25> }
      //#end
      //#if (rr = 2) // posiciona na 2 parte do quarteirao
        object { predio translate <24.0, 0.0, 12.0> scale <0.25, 0.25, 0.25> }
      //#end
    //#end

    //#if (r = 2) // rua a ser inserido o predio = 2
      //#declare i = i+1;
      //#declare gg = seed(pi);
      //#declare rr = ((rand(gg)*1)+1);
      //#if (rr = 1) // posiciona na 1 parte do quarteirao
        object { predio translate <48.0, 0.0, 6.0> scale <0.25, 0.25, 0.25> }
      //#end
      //#if (rr = 2) // posiciona na 2 parte do quarteirao
        object { predio translate <48.0, 0.0, 12.0> scale <0.25, 0.25, 0.25> }
      //#end      
    //#end

    //#if (r = 3) // rua a ser inserido o predio = 3
      //#declare i = i+1;
      object { predio translate <72.0, 0.0, 18.0> scale <0.25, 0.25, 0.25> }
    //#end

    //#if (r = 4) // rua a ser inserido o predio = 4
      //#declare i = i+1;
     //#declare gg = seed(pi);
      //#declare rr = ((rand(gg)*2)+1);
      //#if (rr = 1) // posiciona na 1 parte do quarteirao
        object { predio translate <96.0, 0.0, 6.0> scale <0.25, 0.25, 0.25> }
      //#end
      //#if (rr = 2) // posiciona na 2 parte do quarteirao
        object { predio translate <96.0, 0.0, 12.0> scale <0.25, 0.25, 0.25> }
      //#end      
      //#if (rr = 3) // posiciona na 2 parte do quarteirao
        object { predio translate <96.0, 0.0, 18.0> scale <0.25, 0.25, 0.25> }
      //#end
    //#end

  //#end
 
}