// Persistence of Vision Ray Tracer Scene Description File // File: rec_cube.pov // Vers: 3.5 // Desc: Recursive Cube-Call // Date: some day in 2001 // Auth: Tim Nikias Wenclawiak // Last Update: 23.5.02 (dd.mm.yy) /*Description: The recursive-macro is simple. You initiate it with a size for a cube. The macro then places a superellipsoid in each corner, and calls itself with the settings for the cubes along the edges. As the size of a superellipsoid is a third of the cube, cubes get smaller and smaller the further they are created in the recursive-tree. Along with the superellipsoid, in the first two levels of the recursion, light-sources and emission-media-spheres are placed in the center of their respective cubes. The Macro Recursive_Cubes(Size,Center,Level,Max_Level) In POV, you set a box by defining two corners. This macro uses a different approach: You specify the overall size, and then give a center. When initiating the macro, you should set Level to 0 and Max_Level to the maximum amount of recursions you want. The Level-Value will increase internally and keep track of the recursion-depth, whereas Max_Level is used to check if no new recursions should be initiated. It is left unchanged throughout each call. For each new recursion-level, new sizes (actually simply a third of the initial one) and centers (positions along the edges) are given to the next level. */ //Old gamma value, cause I forgot to use in the old days... global_settings{max_trace_level 20 assumed_gamma 2.2} //Recursive-Macro: Calls itself with values based on the original ones #macro Recursive_Cubes(Size,Center,Level,Max_Level) //Size sets an initial size for the cubes //Level is increased every time the macro is called //Max_Level is always the same and sets the upper limit of recursions //Generating the different locations for the superellipsoids #local Place = array[8] { Size/6*<1,1,1>-Size/2+Center, Size/6*<1,1,5>-Size/2+Center, Size/6*<5,1,1>-Size/2+Center, Size/6*<5,1,5>-Size/2+Center, Size/6*<1,5,1>-Size/2+Center, Size/6*<1,5,5>-Size/2+Center, Size/6*<5,5,1>-Size/2+Center, Size/6*<5,5,5>-Size/2+Center } //Placing the Superellipsoids #local Sphere_Count=1; #while (Sphere_Count <= 8) superellipsoid{<.2,.2> scale (Size.x/6-Size.x/24) translate Place[Sphere_Count-1] hollow} #local Sphere_Count=Sphere_Count+1; #end //Placing media and lightsources inside the recursive-structure //The #if takes care of doing so only in the first two levels, //this doesn't matter for the lightsources, but more so for //the media, of which the size needs to be calculated correctly. //Too many media wouldn't look so good either. #if (Level = 0 | Level = 1) light_source{<0,0,0> #if (Level = 0) rgb x #end #if (Level = 1) rgb <0,.5,1> #end fade_distance (Size.x/6-Size.x/24)*4 fade_power 2 } sphere{0,1 hollow pigment{rgbt <0,0,0,1>} interior{ media{ emission 5 intervals 1 samples 10,10 method 3 density{spherical poly_wave 3 color_map{[0 rgb 0] [.75 #if (Level = 0) rgb x*.5 #end #if (Level = 1) rgb <0,.5,1> #end ] [1 rgb 1] } } } } scale (Size.x/6-Size.x/24)*8 no_shadow } #end //This creates the recursion: //As long as the current level isn't equal to the max_level, we //call the macro with new values for each new recursive-cube #if (Level != Max_Level) //Front Recursive_Cubes(Size/3,Size/6*<3,1,1>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<1,3,1>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<5,3,1>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<3,5,1>-Size/2+Center,Level+1,Max_Level) //Left Side Recursive_Cubes(Size/3,Size/6*<1,1,3>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<1,3,5>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<1,5,3>-Size/2+Center,Level+1,Max_Level) //Right Side Recursive_Cubes(Size/3,Size/6*<5,1,3>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<5,3,5>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<5,5,3>-Size/2+Center,Level+1,Max_Level) //Rear Recursive_Cubes(Size/3,Size/6*<3,1,5>-Size/2+Center,Level+1,Max_Level) Recursive_Cubes(Size/3,Size/6*<3,5,5>-Size/2+Center,Level+1,Max_Level) #end //End of Recursive-Macro #end //Initiating the macro inside a union, cause it returns a bunch o' objects union{ Recursive_Cubes(<1,1,1>,<0,0,0>,0,2) pigment{rgb .4} finish{ reflection .4 specular 1.9 roughness .01 metallic } } camera{location <1.5,-.75,-.76>*1.25 look_at 0} light_source{<-190,110,-220> rgb <.3,.8,.8>} light_source{<60,60,70> rgb <.8,.7,.8>} light_source{<40,-150,-40> rgb .5 //area_light <-5,0,-5><5,0,5>,6,6 }