// another fine background picture
// 10/2014 Christian Perle

#declare A = seed(42);

#declare CamPos = <-.001, .001, -25>;

camera {
	location CamPos
	//up y
	//right 1920/1200*x
	direction 1.5*z
	look_at 0
}

// visible orange light source
union {
	light_source {
		0 color rgb 2
		area_light 1*x, 1*y, 5, 5
		jitter adaptive 1
	}
	sphere {
		0, 1.001
		pigment { rgbf<1, .6, .2, .7> }
		finish { phong .7 phong_size 5 }
	}
	translate 8*z
}

// light source on camera position
light_source {
	CamPos color rgb 0.3
}

// radius for round edges   (0 < Rrad < 1)
#declare Rrad = 0.3;

#declare Rcyl = cylinder {
	<-(1-Rrad), 0, 0>, <1-Rrad, 0, 0>, Rrad
	translate <0, 1-Rrad, -(1-Rrad)>
}

#declare Rbal = sphere { <1-Rrad, 1-Rrad, -(1-Rrad)>, Rrad }

#declare Rhor = merge {
	object { Rcyl }
	object { Rbal }
}

#declare Rcut = box { <-(1-Rrad), -(1-Rrad), -1>, <1-Rrad, 1-Rrad, 1> }

// cube with round edges
#declare Cube = merge {
	merge {  // box without edges
		object { Rcut }
		object { Rcut rotate 90*x }
		object { Rcut rotate <90, 0, 90> }
	}
	// add top round edges
	object { Rhor }
	object { Rhor rotate 90*y }
	object { Rhor rotate 180*y }
	object { Rhor rotate 270*y }
	// add side round edges
	object { Rcyl rotate 90*z }
	object { Rcyl rotate 90*z rotate 90*y }
	object { Rcyl rotate 90*z rotate 180*y }
	object { Rcyl rotate 90*z rotate 270*y }
	// add bottom round edges
	object { Rhor rotate <180, 0, 0> }
	object { Rhor rotate <180, 90, 0> }
	object { Rhor rotate <180, 180, 0> }
	object { Rhor rotate <180, 270, 0> }
	bounded_by { box { <-1.01, -1.01, -1.01>, <1.01, 1.01, 1.01> } }
	scale 0.5
}

// random cube array
union {
#declare Z = 0;
#while (Z<10)
	#declare Y = -15 + mod(Z,2);
	#while (Y<15)
		#declare X = -15 + mod(Y,2);
		#while (X<15)
			#if (rand(A)<0.5)
			object {
				Cube
				translate <X, Y, Z>
			}
			#end
			#declare X = X+2;
		#end
		#declare Y = Y+2;
	#end
	#declare Z = Z+1;
#end
	pigment { rgb .1 }
	finish { phong .7 phong_size 5 reflection .5 }
	normal { wrinkles .3 scale .2 }
	rotate 30*z
	translate -5*z
}