// Bits of cereal sticking out of some milk //#include "colors.inc" #include "math.inc" camera {location <0, 0.2, -0.4> look_at <0, 0, 0>} light_source { <0, 50, -10> color rgb <1,1,1>} light_source { <-20, 5, -10> color rgb <1,1,1>} #declare Quantity = 70; #declare BowlDiameter = 0.5; #declare Cereal = array[Quantity]; #declare CerealSeed = seed(42); #declare CerealTexture = texture { pigment {agate scale 0.01 color_map { [0.5 color rgb <1,0.9,0.6>] [1.0 color rgb <0.8,0.6,0.3>] } } } // The Breakfast object will be a union of all of the individual pieces of cereal. #declare Breakfast = union { #local i=0; #while (i translate <(0.44*BowlDiameter*pow(rand(CerealSeed),0.5))+0.018*BowlDiameter,0,0> rotate y*rand(CerealSeed)*360 texture {CerealTexture} } // We then check whether it collides with any of the other pieces that we've already defined #local Collision = 1; #while (Collision = 1) #local Collision = 0; #local j = 0; #while(j0) #local X=min_extent(TempObject).x; #while(X)) #local Collision = 1; // If this bit of cereal collides with another, we move it up a bit and around 20 degrees #declare Cereal[i] = object {Cereal[i] translate y*0.001 rotate y*20} #local X=max_extent(TempObject).x; #local Y=max_extent(TempObject).y; #local Z=max_extent(TempObject).z; #end #local Z = Z+0.01; #end #local Y = Y+0.01; #end #local X = X+0.01; #end #end #end #local j = j + 1; #end #end // The following line adds the relocated piece of cereal to the Breakfast object object {Cereal[i]} #local i = i + 1; #end } // End of Breakfast object definition object {Breakfast} cylinder {0,<0,0.005,0>,BowlDiameter/2 texture {pigment {color <1,1,1>} normal {bumps scale 0.02}} }