#include "colors.inc"
#include "sunpos.inc"
#include "woods.inc" // T_Wood1 - T_Wood35
#include "metals.inc"
#include "skies.inc" 
#include "glass.inc"
#include "rand.inc"

#declare fonte=seed(314159);

global_settings {
  assumed_gamma 1.3
  max_trace_level 7
}

sky_sphere {
  S_Cloud1
}

light_source {
  0
  color rgb 2    
  area_light
  <4, 0, 0> <0, 0, 4> 
  4, 4                
  adaptive 0          
  jitter              
  translate <-10, 100, -10>
}

#declare finish_metal =
finish {
        ambient .1
        diffuse .1
        specular 1
        roughness .001
        metallic
        reflection {
          .3
          metallic
        }
     }

#declare prata = 
material {
    texture { 
    pigment { Silver } 
    finish { finish_metal }
  }
} 

#declare preto_metal = 
material {
    texture { 
    pigment { Black } 
    finish { finish_metal }
  }
}

#declare azul_metal = 
material {
    texture { 
    pigment { Blue } 
    finish { finish_metal }
  }
}

#declare vermelho_metal = 
material {
    texture { 
    pigment { Red } 
    finish { finish_metal }
  }
}

#declare amarelo_metal = 
material {
    texture { 
    pigment { Yellow } 
    finish { finish_metal }
  }
}

#declare marrom_metal = 
material {
    texture { 
    pigment { Brown } 
    finish { finish_metal }
  }
}

#declare vidro1 =
material {
  texture {
    pigment {rgbt 1}
    finish {
      ambient 0.0
      diffuse 0.05
      specular 0.6
      roughness 0.005
      reflection {
        0.1, 1
        fresnel on
      }
      conserve_energy
    }
  }
  interior {
    ior 1.5
    fade_power 1001
    fade_distance 0.9
    fade_color 0.9
  }
}

#declare void = 
material {
    texture { 
    pigment { rgbt 0 } 
    finish {
        ambient .1
        diffuse .1
        specular 1
        roughness .001
        metallic
        reflection {
          .9
          metallic
        }
     }
  }
}

#declare vidro2 = 
material {
	texture {
    pigment { rgb <0.2, 0.2, 0.9>}
    finish {
      ambient 0.0
      diffuse 0.05
      specular 0.6
      roughness 0.005
      reflection {
        0.1, 1.0
        fresnel on
      }
      conserve_energy
    }
  }
  interior {
    ior 1.5
    fade_power 1001
    fade_distance 0.9
    fade_color <0.5,0.5,0.9>
  }
}

#declare metalDT = 
material {
        texture {
                pigment {
                        color DarkTurquoise
                }
                finish {
                        diffuse 0.3
                        ambient 0.0
                        specular 0.6
                        reflection {
                                0.8
                                metallic
                        }
                        conserve_energy
                }
        }
}

#declare metalNMB = 
material {
        texture {
                pigment {
                        color NewMidnightBlue
                }
                finish {
                        diffuse 0.3
                        ambient 0.0
                        specular 0.6
                        reflection {
                                0.8
                                metallic
                        }
                        conserve_energy
                }
        }
}



#declare metalDSG = 
material {
        texture {
                pigment {
                        color DarkSlateGrey
                }
                finish {
                        diffuse 0.3
                        ambient 0.0
                        specular 0.6
                        reflection {
                                0.8
                                metallic
                        }
                        conserve_energy
                }
        }
}
  
#declare vidroDSB =
material {
  texture {
    pigment {rgbt 1}
    finish {
      ambient 0.0
      diffuse 0.05
      specular 0.6
      roughness 0.005
      reflection {
        0.1, 1.0
        fresnel on
      }
      conserve_energy
    }
  }
  interior {
    ior 1.5
    fade_power 1001
    fade_distance 0.9
    fade_color Col_Sapphire_01
  }
}

#declare ouro = 
material {
    texture { 
    pigment { BrightGold } 
    finish {
        ambient .1
        diffuse .1
        specular 1
        roughness .001
        metallic
        reflection {
          .9
          metallic
        }
     }
  }
}


#declare vidroDSG =
material {
  texture {
    pigment {rgbt 1}
    finish {
      ambient 0.0
      diffuse 0.05
      specular 0.6
      roughness 0.005
      reflection {
        0.1, 1.0
        fresnel on
      }
      conserve_energy
    }
  }
  interior {
    ior 1.5
    fade_power 1001
    fade_distance 0.9
    fade_color DarkSlateGrey
  }
}

plane {	<0, 1, 0>, 0 texture { T_Wood1 } }

#declare conector =
cylinder {
	<-5, 0.5, 0>, <5, 0.5, 0>, 0.2
	material { vidroDSG }
}

#declare pacote_torus =
torus {
	0.2, 0.05
	material { amarelo_metal }
	finish { ambient 0.9 }
	rotate <90, 90, 0>
	scale 1/2
	translate <0, 0.5, 0>  // já na altura certa
}

#declare pacote_caixa =
box {
	<-0.2, 0, -0.2>, <0.2, 0.4, 0.2>
	material { vermelho_metal }
	finish { ambient 0.9 }
	scale 1/2
	translate <0, 0.4, 0>  // já na altura certa
}

#declare pacote_esfera = 
sphere {
	<0, 0, 0>, 0.2
	material { azul_metal }
	finish { ambient 0.9 }
	scale 1/2
	translate <0, 0.5, 0>
}

#declare xx = 0;
#declare limite = 3;
#while (xx < limite)
	#declare zz = 0;
	#while (zz < limite)
		union { //desenha o cpu
			box {
				<-2, 0, -2>, <2, 1, 2> //base do cpu
				#declare qual = 3*rand(fonte);
				#if (qual < 3 & qual >= 2)
					material { metalDSG }
				#end
				#if (qual < 2 & qual >= 1)
					material { metalDT }
				#end
				#if (qual < 1)
					material { metalNMB }
				#end

			}
			box {
				<-0.1, 0.99, -0.1>, <0.1, 1.3, 0.1> //suporte monitor
				material { void }
			}
			union {	//monitor
				box {
					<-1, 1.3, -1>, <1, 3.3, 1>
					material { vidroDSG }
				}
				#declare qual = 3*rand(fonte);
				#if (qual < 3 & qual >= 2)
					object { pacote_caixa finish { ambient  0.4 } scale 6 translate <0, 3, 0> }
				#end
				#if (qual < 2 & qual >= 1)
					object { pacote_torus finish { ambient 0.4 } scale 6 translate <0, 3, 0> }
				#end
				#if (qual < 1)
					object { pacote_esfera finish { ambient 0.4 } scale 6 translate <0, 3, 0> }
				#end
			}
			translate <xx*10, 0, zz*10> 
		}
		#if (xx < limite - 1)
			union { 
				object { conector }
				#declare quantos = 10;
				#declare jah = 0;
				#while (jah < quantos) 
					#declare qual = 4*rand(fonte);
					//3 <= x < 4 = nao tem pacote
					#if (qual < 3 & qual >= 2) 
						object { pacote_torus translate <-5 + jah, 0, 0> }
					#end
					#if (qual < 2 & qual >= 1) 
						object { pacote_caixa translate <-5 + jah, 0, 0> }
					#end
					#if (qual < 1 & qual >= 0) 
						object { pacote_esfera translate <-5 + jah, 0, 0> }
					#end
					#declare jah = jah + 1;
				#end
				translate <5+10*xx, 0, 10*zz> 
			}
		#end
		#if (zz < limite - 1)
			union { 
				object { conector }
				#declare quantos = 10;
				#declare jah = 0;
				#while (jah < quantos) 
					#declare qual = 4*rand(fonte);
					//3 <= x < 4 = nao tem pacote
					#if (qual < 3 & qual >= 2) 
						object { pacote_torus translate <-5 + jah, 0, 0> }
					#end
					#if (qual < 2 & qual >= 1) 
						object { pacote_caixa translate <-5 + jah, 0, 0> }
					#end
					#if (qual < 1 & qual >= 0) 
						object { pacote_esfera translate <-5 + jah, 0, 0> }
					#end
					#declare jah = jah + 1;
				#end
				rotate <0, 90, 0> translate <10*xx, 0, 5+10*zz>
			}
		#end
		#declare zz=zz+1;
	#end
	#declare xx=xx+1;
#end


camera {
  location  <-10,20,-10>
  look_at   <10,0,10>
}