/////////////////////////////////////////////////////////////////////////////////////////////////////// // Includes #include "arrays.inc" #include "rand.inc" /////////////////////////////////////////////////////////////////////////////////////////////////////// // Constants #declare Max_Level = 5; #declare Max_Subtextures = 5; #declare Max_Layers = 5; #declare Use_Std_Pigment = 1; // If set will generate a random pigment, otherwise it // will pick one from list(s) #declare Use_Random_Pattern = 1; // If set will pick a random pattern #declare Fixed_Pattern = "wood"; // What to use if Use_Random_Pattern = 0 #declare Random_Pattern_Mod = 1; // Allows random mods to a pattern /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit #macro Emit(String) #write(rndtxt,String) #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Integer #macro Emit_Integer(The_Integer) #write(rndtxt,str(floor(The_Integer),0,0)) #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Float #macro Emit_Float(The_Float) #write(rndtxt,str(The_Float,0,5)) #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Pattern #macro Emit_Pattern() #if (Use_Random_Pattern = 1) #local Pattern_Index = RRand(0,20,the_seed); #switch (ceil(Pattern_Index)) #case (1) Emit("agate") #break #case (2) Emit("boxed") #break #case (3) Emit("bozo") #break #case (4) Emit("bumps") #break #case (5) Emit("cells") #break #case (6) Emit("crackle") #break #case (7) Emit("cylindrical") #break #case (8) Emit("dents") #break #case (9) Emit("granite") #break #case (10) Emit("leopard") #break #case (11) Emit("marble") #break #case (12) Emit("onion") #break #case (13) Emit("planar") #break #case (14) Emit("quilted") #break #case (15) Emit("radial") #break #case (16) Emit("ripples") #break #case (17) Emit("spherical") #break #case (18) Emit("waves") #break #case (19) Emit("wood") #break #case (20) Emit("wrinkles") #break #end #else Emit(Fixed_Pattern) #end #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_3_Vector #macro Emit_3_Vector() Emit("<") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(">") #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_RGBT_Vector #macro Emit_RGBT_Color(T_Limit) Emit("<") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(T_Limit/2,T_Limit,the_seed)) Emit(">") #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Pattern_Modifier #macro Emit_Pattern_Modifier(Indent,Pos_Factor) #if (Random_Pattern_Mod = 1) // Wave? #if (RRand(0,1,the_seed) > 0.5) #local Wave_Index = RRand(0,4,the_seed); Emit(Indent) #switch (ceil(Wave_Index)) #case (1) Emit("sine_wave\n") #break #case (2) Emit("scallop_wave\n") #break #case (3) Emit("cubic_wave\n") #break #case (4) Emit("poly_wave\n") #break #end #end // Frequency? #if (RRand(0,1,the_seed) > 0.5) Emit(Indent) Emit("frequency ") Emit_Float(RRand(0.0001,2,the_seed)) Emit("\n") #end // Scale? #if (RRand(0,1,the_seed) > 0.5) Emit(Indent) Emit("scale ") Emit_3_Vector() Emit(" * ") Emit_Float(RRand(0.0001,2,the_seed)) Emit("\n") #end //Rotate? #if (RRand(0,1,the_seed) > 0.5) Emit(Indent) Emit("rotate ") Emit_3_Vector() Emit(" * ") Emit_Float(RRand(0.0001,360,the_seed)) Emit("\n") #end //Translate? #if (RRand(0,1,the_seed) > 0.5) Emit(Indent) Emit("translate (") Emit_3_Vector() Emit(" - ") Emit_3_Vector() Emit(") * ") Emit_Float(RRand(0.0001,2,the_seed)) Emit("\n") #end #else // Use the same mod each time Emit(Indent) Emit("rotate ") Emit_3_Vector() Emit(" * 10 * ") Emit_Float(Pos_Factor) Emit("\n") #end #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Texture_List #macro Emit_Texture_List(Current_Level,Num_Subtextures) // Create array of pattern points #local Pattern_Points = array[Num_Subtextures]; // Fill it with random points #local Pattern_Index = 0; #while (Pattern_Index < Num_Subtextures) #local Pattern_Points[Pattern_Index] = RRand(0,1,the_seed); #local Pattern_Index = Pattern_Index + 1; #end // Sort pattern points into order Sort_Array(Pattern_Points) // Emit the pattern and its map Emit("\t") Emit_Pattern() Emit("\n") Emit("\ttexture_map {\n") #local Pattern_Index = 0; #while (Pattern_Index < Num_Subtextures) Emit("\t\t[") Emit_Float(Pattern_Points[Pattern_Index]) Emit("\t") Emit("texture_") Emit(Current_Level+1) Emit("_") Emit(Pattern_Index+1) Emit("] \n") #local Pattern_Index = Pattern_Index + 1; #end Emit("\t}\n") Emit_Pattern_Modifier("\t",Current_Level) #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Pick_Color_Function #macro Pick_Color_Function() #local Color_Function = RRand(0,2,the_seed); #switch (ceil(Color_Function)) #case (1) #declare Selected_Color_Function = "orange"; #declare Selected_Color_T_Function = "orange_t"; #break #case (2) #declare Selected_Color_Function = "purple"; #declare Selected_Color_T_Function = "purple_t"; #break #end #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Pigment_List #macro Emit_Pigment_List(Num_Pigments,Current_Layer,Layer_Limit) // Create array of pattern points #local Pattern_Points = array[Num_Pigments]; // Fill it with random points #local Pattern_Index = 0; #while (Pattern_Index < Num_Pigments) #local Pattern_Points[Pattern_Index] = RRand(0,1,the_seed); #local Pattern_Index = Pattern_Index + 1; #end // Sort pattern points into order Sort_Array(Pattern_Points) // Emit the pattern and its map Emit("\t\t") Emit_Pattern() Emit("\n") Emit("\t\tpigment_map {\n") #local Pattern_Index = 0; Pick_Color_Function() #while (Pattern_Index < Num_Pigments) Emit("\t\t\t[") Emit_Float(Pattern_Points[Pattern_Index]) Emit("\tcolor") #if (Current_Layer = 1) Emit(" ") #if (Use_Std_Pigment = 1) Emit("rgb ") Emit_3_Vector() #else Emit(Selected_Color_Function) Emit("(") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(")") #end #else Emit(" ") #if (Use_Std_Pigment = 1) Emit("rgbt ") Emit_RGBT_Color(Current_Layer/Layer_Limit) #else Emit(Selected_Color_T_Function) Emit("(") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(",") Emit_Float(RRand(0,1,the_seed)) Emit(")") #end #end Emit("] \n") #local Pattern_Index = Pattern_Index + 1; #end Emit("\t\t}\n") Emit_Pattern_Modifier("\t\t",Current_Layer) #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Generate_Texture #macro Generate_Texture(Current_Level, Current_Sub, Max_Level) #if (Current_Level < Max_Level) // Recursive #local Subtexture_Index = 1; #local Num_Subtextures = RRand(1,Max_Subtextures,the_seed); #local Num_Subtextures = ceil(Num_Subtextures); // Generate subtextures #local New_Current_Level = Current_Level+1; #while (Subtexture_Index <= Num_Subtextures) #local New_Subtexture_Index = Subtexture_Index; Generate_Texture(New_Current_Level,Subtexture_Index,Max_Level) #local Subtexture_Index = Subtexture_Index + 1; #end Emit("#declare texture_") Emit_Integer(New_Current_Level-1) Emit("_") Emit_Integer(Current_Sub) Emit("= // Gathering texture\n") Emit("texture {\n") Emit_Texture_List(New_Current_Level-1,Num_Subtextures) Emit("}\n\n") #else // Generate base pigmented texture Emit("#declare texture_") Emit_Integer(Current_Level) Emit("_") Emit_Integer(Current_Sub) Emit(" = // Base pigment texture\n") // How many layers to use #local Num_Layered_Textures = ceil(RRand(1,Max_Layers,the_seed)); #local Layer_Index = 1; #while (Layer_Index <= Num_Layered_Textures) // Texture body Emit("texture {\n") Emit("\tpigment {\n") #local Num_Colors = ceil(RRand(1,Max_Subtextures,the_seed)); Emit_Pigment_List(Num_Colors,Layer_Index,Num_Layered_Textures) Emit("\t}\n") Emit("\tfinish {\n") Emit("\t\tdiffuse ") Emit_Float(RRand(0.5,1,the_seed)) Emit("\n\t\tambient ") Emit_Float(RRand(0.25,0.75,the_seed)) Emit("\n\t}\n") Emit("}\n") #local Layer_Index = Layer_Index+1; #end #end #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Emit_Color_Grad_Definition #macro Emit_Color_Grad_Definition(name,color_1,color_2,use_t) Emit("#declare ") Emit(name) Emit(" =\n") Emit("function {\n") Emit("\tpigment {\n") Emit("\t\tgradient y\n") Emit("\t\tpigment_map{\n") #if (use_t) Emit("\t\t\t[0 rgbt <") #else Emit("\t\t\t[0 rgb <") #end Emit_Float(color_1.red) Emit(",") Emit_Float(color_1.green) Emit(",") Emit_Float(color_1.blue) #if (use_t) Emit(",") Emit_Float(color_1.t) #end Emit(">]\n") #if (use_t) Emit("\t\t\t[1 rgbt <") #else Emit("\t\t\t[1 rgb <") #end Emit_Float(color_2.red) Emit(",") Emit_Float(color_2.green) Emit(",") Emit_Float(color_2.blue) #if (use_t) Emit(",") Emit_Float(color_2.t) #end Emit(">]\n") Emit("\t\t}\n") Emit("\t}\n") Emit("}\n\n") #end /////////////////////////////////////////////////////////////////////////////////////////////////////// // Random_Texture #macro Random_Texture(file_name,seed_start) #debug concat("Generating ",file_name," ...\n") // Init #declare the_seed = seed(seed_start); #fopen rndtxt concat(file_name,".pov") write // Test camera Emit("camera {\n") Emit("\tultra_wide_angle\n") Emit("\tlocation <0,0,0>\n") Emit("\tlook_at <0,0,1>\n") Emit("\tup<0,1,0>\n") Emit("\tright<1,0,0>\n") Emit("\tangle 360\n") Emit("\trotate ") Emit_3_Vector() Emit(" * 360\n") Emit("}\n\n") // Test light Emit("light_source {\n") Emit("\t<0,0,0>\n") Emit("\tcolor rgb 1\n") Emit("}\n\n") #if (Use_Std_Pigment = 0) Emit_Color_Grad_Definition("orange",<1,0,0>,<1,1,0>,false) Emit_Color_Grad_Definition("orange_t",<1,0,0,0.9>,<1,1,0,0.1>,true) Emit_Color_Grad_Definition("purple",<1,0,0>,<0,0,1>,false) Emit_Color_Grad_Definition("purple_t",<1,0,0,0.9>,<0,0,1,0.1>,true) #end #local Level_Limit = RRand(1,Max_Level,the_seed); #local Level_Limit = ceil(Level_Limit); // Generate the random texture Generate_Texture(1,1,Level_Limit) Emit("sphere{\n") Emit("\t<0,0,0>,5\n") Emit("\ttexture{texture_1_1}\n") Emit("\thollow\n") Emit("}\n\n") #fclose rndtxt #end /////////////////////////////////////////////////////////////////////////////////////////////////////// Random_Texture(str(frame_number,0,0),frame_number)