// Fabio Negrello - exercicio 05
// ultima modificacao 09/11/00

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

light_source {
  < 40.00, 30.00, -35.00 >
  color rgb < 1.50, 1.50, 1.50 >
} 

camera {
  location  < 40.00, 30.00, -35.00 >
  look_at   < 0.00, 10.00, 0.00 >
} 
  

#declare jw = 2;
#declare jh = 3;
#declare pw = 10;
#declare ph = 30;
#declare pl = 10;
#declare st = seed(pi);
#declare pc = 1;
#declare jc = 1;

#declare janela =

	box {
		<0,0,0>
		<jw,jh,0.5>
		texture { pigment { color rgb < jc, 0.00, jc > } }
	}

#declare corteMeio =
	box {
		<(jw - 0.1),-1,-2>
		<(jw + 0.1),(jh+1),2>
		texture { pigment { color rgb < 0.00, 1.00, 0.00 > } }
	}

#declare jdetalhe =

  	sphere {
    		< (jw/2), jh, 0.00 >, (jw/2)
    		scale < 1, (1/(jw/2)), 1 >
    		texture { pigment { color rgb < 1, 0.00, 0.00 > } }
  	}

#declare corteDetalhe =
	box {
		<0,0,-jh>
		<jw,jh,jh>
		texture { pigment { color rgb < 1.00, 0.00, 0.00 > } }
	}

#declare corteDetalhe02 =
	box {
		<-1,-1,-1>
		<jw+1,jh+jw+1,0>
		texture { pigment { color rgb < 1.00, 0.00, 0.00 > } }
	}

#declare corteDetalhe03 =
	box {
		<-1,0,0>
		<jw+1,jh+jw+1,0>
		texture { pigment { color rgb < 1.00, 0.00, 0.00 > } }
	}

#declare predio =
	box {
		<0,0,0>
		<pw,ph,pl>
		texture { pigment { color rgb < 0.00, 0.00, pc > } }
	}

#declare porta =
	box {
		<(pw/2)-1,0,0>
		<(pw/2)+1,jh,0.1>
		texture { pigment { color rgb < 1.00, 1.00, 0.00 > } }
		translate <0,0,-0.2>
	}

#declare topo =
	box {
		<0,0,0>
		<(pw/2),2,(pl/2)>
		texture { pigment { color rgb < 0.00, 0.00, 0.50 > } }
	}



	
#declare semente = seed(pi);

union {

	#declare nump = 0;
	#while (nump<4)	

	union{
		#declare pc = rand(st);

		union {
			object{ predio }
			object{ porta }
			object{ topo 
				translate <pw/4,ph,pl/4>
			}
		}
	
		#declare nandar = ph/6;
		#declare j = 0;
		#while (j<nandar)
			union {
			#declare njanela = int(pw/3);
			#declare i = 0;
			#while (i<njanela) 
				#declare jc = rand(st);
				difference {
					object {janela}
					object {corteMeio}
					translate <1+(i*3),5+(j*5),-0.2>
				}
				difference{
					object {jdetalhe}
					object {corteDetalhe}
					object {corteDetalhe02}	
					object {corteDetalhe03}
					translate <1+(i*3),5+(j*5),-0.2>
				}
				#declare i = i + 1;
			#end
			
			#declare njanela = int(pl/5);
			#declare i = 0;			
			#while (i<njanela) 
				difference {
					object {janela}
					object {corteMeio}
					rotate <0,-90,0>
					translate <0.2+pw,5+(j*5),1+(i*3)>
				}
				difference{
					object {jdetalhe}
					object {corteDetalhe}
					object {corteDetalhe02}	
					object {corteDetalhe03}
					rotate <0,-90,0>
					translate <0.2+pw,5+(j*5),1+(i*3)>
				}
				#declare i = i + 1;
			#end



			#declare j = j + 1;
		}
		#end
	translate<(nump-2)*(pw+5),0,0>
	}
	#declare nump = nump + 1;
	#end

}