// Exercicio 7 de laboratorio - 16/11/2000
// Marilia Goulart Honorio - 971259

#include "colors.inc"

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

light_source {
  < 30.00, 20.00, 20.00 >
  color rgb < 1.00, 1.00, 1.00 >
}


camera {
//  location  <  40.00, 16.00, 8.00 >
//  location  <  16.00, 26.00, 6.00 >
  location  <  66.00, 18.00, 15.00 >
  right     < -1.20, 0.00, 0.00 >
  up        <  0.00, 0.00, 0.90 >
  sky       <  0.00, 0.00, 1.00 >
//  look_at   <  2.00, 2.00, 8.00 >
  look_at   <  4.00, 16.00, 8.00 >
}

//  camera {
//    location <45, 5, -35>
//    look_at 0
//  }

//  background { color rgb <0.5,0.5,1> }  //to make the patch easier to see

//  light_source { <300, 300, -700> White }

//  plane { y, -12
//    texture {
//      pigment {
//        checker
//        color Green
//        color Yellow
//      }
//    }
//  }


#declare TeePeeTex =
  texture {
    pigment {
      color rgb <1, 0.65, 0.65,>
    }
    finish {
      ambient .2
      diffuse .6
    }
  }

#declare n = 6; // numero de andares
#declare r = 2; // numero de janelas na fachada
#declare s = 3; // numero de janelas na lateral

#declare p = 2; // numero de ruas norte-sul
#declare q = 2; // numero de ruas leste-oeste
#declare i = 1;

#declare predio =
  box{
    <2*s+1, 2*r+1, 0>,
    <0, 0, 2*n+2>
    texture { pigment { Blue } }
  }

#declare CloudArea = texture {
    pigment {
      agate
      turbulence 1
      lambda 2
      frequency 2
      color_map {
        [0.0 color rgbf <1, 1, 1, 1>]
        [0.5 color rgbf <1, 1, 1, .35>]
        [1.0 color rgbf <1, 1, 1, 1>]
      }
    }
  }

#declare OceanArea = texture {
      pigment {
        bozo
        turbulence .5
        lambda 2
        color_map {
          [0.00, 0.33 color rgb <0, 0, 1>
                      color rgb <0, 0, 1>]
          [0.33, 0.66 color rgbf <1, 1, 1, 1>
                      color rgbf <1, 1, 1, 1>]
          [0.66, 1.00 color rgb <0, 0, 1>
                      color rgb <0, 0, 1>]
        }
      }
    }

#declare LandArea = texture {
      pigment {
        agate
        turbulence 1
        lambda 1.5
        omega .8
        octaves 8
        color_map {
          [0.00 color rgb <.5, .25, .15>]
          [0.33 color rgb <.1, .5, .4>]
          [0.86 color rgb <.6, .3, .1>]
          [1.00 color rgb <.5, .25, .15>]
        }
      }
    }

#declare terreo =
  union{
    box{
      <2*s+1, 2*r+1, 0>,
      <0, 0, 2>
      texture { pigment { Gray } }
    }
    box{
      <2*s+1.1, r+1, 0>,
      <2*s+1.1, r, 1>
      texture { pigment { Blue } }
    }
  }

#declare andar =
  union{
    box{
      <2*s+1, 2*r+1, 2*i>,
      <0, 0, 2*i+2>
      texture { pigment { Red } }
    }
//    box{
//      <2*s+1.1, r+1, 0>,
//      <2*s+1.1, r, 1>
//      texture { pigment { Green } }
//    }
  }


#declare CloudArea = texture {
    pigment {
      agate
      turbulence 1
      lambda 2
      frequency 2
      color_map {
        [0.0 color rgbf <1, 1, 1, 1>]
        [0.5 color rgbf <1, 1, 1, .35>]
        [1.0 color rgbf <1, 1, 1, 1>]
      }
    }
  }

#declare ruaLO =
union{
  box{
    <9,33,0>,
    <7,-2,0>
    texture { pigment { Black } }
  }
  #declare p = 1;
  #while (p <= 16)
    box{
      <8.25, 1, 0>,
      <7.75, 0, 0>
      texture { pigment { White } }
      translate <0, 2*p, 0>
    }
    #declare p = p + 1;
  #end
}

#declare ruaNS =
  union{
    box{
      <-2,9,0>,
      <80,7,0>
      texture { pigment { Black } }
    }
    #declare p = 1;
    #while (p <= 16)
      box{
        <0, 8.25, 0>,
        <1, 7.75, 0>
        texture { pigment { White } }
        translate <2*p, 0, 0>
      }
      #declare p = p + 1;
    #end
  }



// Aqui está a cena, finalmente:


union
{
  object { ruaLO }
  object { ruaLO
           translate <12,0,0>
         }
  object { ruaLO
           translate <22,0,0>
         }
  object { ruaNS }
  object { ruaNS
           translate <0,12,0>
         }
  object { ruaNS
           translate <0,22,0>
         }

  #declare i = 1;
  #declare aux = 1;
  #declare g = seed(8);

  #while (aux <= 6)
// comeco
    #declare andares = rand(g);
    #declare janelasF = rand(g);
    #declare janelasL = rand(g);

    #declare andares = int(andares*10);
    #declare janelasF = int(janelasF*10);
    #declare janelasL = int(janelasL*10);

    object { terreo }

    #while ( i <= n )
      // andar
      #declare j = 1;
      #declare k = 1;
      union{
        box{
          <2*s+1, 2*r+1, 2*i>,
          <0, 0, 2*i+2>
          texture { pigment { Gray } }
        }
        // janelas da fachada
        #while ( j <= r )
          box{
            <2*s+1.1, 2*j, 2*i>,
            <2*s+1.1, 2*j-1, 2*i+1>
            texture { pigment { Black } }
          }
          #declare j = j + 1;
        #end

        // janelas da lateral
        #while ( k <= s )
          box{
            <2*k-1 ,2*r+1.1, 2*i>,
            <2*k ,2*r+1.1, 2*i+1>
            texture { pigment { Black } }
          }
          #declare k = k + 1;
        #end

      }
      #declare i = i + 1;
    #end
// fim
  #declare aux = aux + 1;
  #end
 }