// Last edited on 2003-04-12 09:33:26 by stolfi

#include "colors.inc"
#include "stones.inc"

background{ color rgb < 0.00, 0.03, 0.15 > }

#declare ctr = < 0.00, 0.00, 2.00 >;
#declare cam = < 5.00, 1.00, 1.00 >;

camera {
  location  ctr + 4.0*cam
  right     1.2*x up 0.4*y 
  sky       <  0.00, 0.00, 1.00 >
  look_at   ctr
} 

light_source {
  20*<5,5,7>
  color rgb 0.8*< 1.00, 1.00, 1.00 >
} 

light_source {
  20*<5,-5,8>
  color rgb 0.8*< 1.00, 1.00, 1.00 >
} 

light_source {
  20*<1,1,9>
  color rgb 0.8*< 1.00, 1.00, 1.00 >
} 

light_source {
  ctr + 10*(vrotate(cam, 20*z) + 5*z)
  color rgb 0.4*< 1.00, 1.00, 1.00 >
} 

light_source {
  ctr + 10*(vrotate(cam, -70*z) + 6*z)
  color rgb 0.4*<1,1,1>
}

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

// cores/texturas

#declare cor_metal = <.8,.8, 1>;
#declare tx_metal = 
texture {
  pigment {rgb cor_metal}
  finish {
    ambient 0.05 diffuse 0.05
    reflection cor_metal
    specular 0.20 roughness 0.05
      }
}
 

#declare cor_cristal = <0,1,0>;
#declare tx_cristal =
texture {
  finish {
    ambient 0.1 diffuse 0.1
    reflection 0.25
    specular 1 roughness 0.001
  }
  pigment { color cor_cristal filter 1}
}

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

#declare tinta_vermelha =
  texture {
    pigment { color rgb < 1.00, 0.00, 0.00 > }
  }

#declare tinta_preta =
  texture {
    pigment { color rgb < 0.00, 0.00, 0.00 > }
  }
#declare tinta_verde =
  texture {
    pigment { color rgb < 0.00, 1.00, 0.00 > }
  }


// objetos


#declare cabeca_robo = 
union {
  difference {
    blob { threshold 0.7
	cylinder {<0,0,-0.3>,<0,0,0.3>, 0.5, 1}
        cylinder {<0,0,-0.7>,<0,0,-0.3>, 0.1, 1}
        cylinder {<0.1,0,-0.9>,<0.1,0,-0.7>, 1.5, 0.2}
      }
    cylinder {<-0.3,0.3,-0.2>, <-0.3,0-0.3,-0.2>, 0.1 }
    texture{tinta_verde}
  }
  cylinder {<-0.24,0.1, 0.1>, <0.2,0.1,0.1>, 0.07 texture{tinta_preta}}
  cylinder {<-0.24,-0.1, 0.1>, <0.2,-0.1,0.1>, 0.07 texture{tinta_preta}}
  scale <1, 1, 0.7>
}



#declare ger = seed(434123);
#declare estante = 
    union {	 
	box {<0,0,0> <-10, 0.1, 4> texture{tinta_azul}}
	#declare i = 0.25;
	#while (i < 4)
	  // prateleiras
	  box {<0, 0.1, i> <-10, 1.0, i+0.1> texture{tx_metal}}
	  box {<0, 0.0, i> <-10,-0.9, i+0.1> texture{tx_metal}}
	#declare i = i + 1;
	#end

	// produtos
	#declare i = 0.25;
	#while (i < 4)
	    #declare j = -0.5;
	    #while (j > -9.5)
	       #declare msphere = 
	           sphere {<j, 0.49, i+0.5> 0.4 texture{tinta_vermelha}}
	       #declare mbox = 
	           box {<j+.4, 0.15, i>, <j-0.4, 0.95, i+0.8> texture{tinta_azul}}

	       #declare op = rand(ger)*3;
	       #if (op < 1)
	           object{mbox}
	           object{msphere scale <1, -1, 1>}
	       #else 
	         #if (op < 2)
	           object{msphere}
	           object{mbox scale <1, -1, 1>}
	         #else
	           object {cabeca_robo translate <j, 0.49, i+0.5>}
	           object {cabeca_robo translate <j, 0.49, i+0.5> scale <1, -1, 1>}
	         #end
	       #end
	       #declare j = j - 1;
	    #end
	   #declare i = i + 1;
       #end
    }




// Aqui está a cena, finalmente:

union {
    #declare i = -14;
    #while (i < 14)
    object {estante translate <0, i, 0>}
    #declare i = i + 5;
    #end
}