global_settings { assumed_gamma 1.5 } default { pigment { rgb <1,0.9,0.8> } } background { rgb 1 } #declare h = 0.8; //height #declare Type = 1; //1 or 2 #macro base_shape(X,Y,Z,Type) #local T=; #if(Type!=2) triangle {} triangle {} #end triangle { ,T, } triangle { ,T, } triangle {,T,} triangle {,T,} #if(Type=2) #local B=; triangle { ,B, } triangle { ,B, } triangle {,B,} triangle {,B,} #end #end #declare Level1=mesh{ #local X=0; #while (X<2) #local Z=0; #while (Z<2) base_shape(X,0,Z,Type) #local Z=Z+1; #end #local X=X+1; #end base_shape(.5,h,.5,Type) #if(Type=2) base_shape(.5,-h,.5,Type) #end scale 1/2 } #macro Pyramid(a,Lvl) #declare b = union { #local X=0; #while (X<2) #local Z=0; #while (Z<2) object { a translate } #local Z=Z+1; #end #local X=X+1; #end object { a translate <.5,h,.5> } #if(Type=2) object { a translate <.5,-h,.5> } #end #if (Lvl>1) scale 1/2 #end } #undef a #if (Lvl>1) Pyramid(b,Lvl-1) #else object {b} #end #end camera { #switch(Type) #case(1) location <3.3,h/2,2.3> //location <1,h/2,2> look_at <.5,h*(2/3),.5> angle 70 #break #case(2) location <3.3,h/2,2.3>*1.2 look_at <.5,0,.5> #break #end } light_source { <100,100,0> color rgb 1} light_source { <0,-100,2> color rgb 0.5 shadowless} // Usage: // Pyramid (A declared object , Level of recursion ) object { Pyramid( Level1 , 4 ) }