/*Pov-Ray : 3.8 Scene File : lsys.pov Author : Ingo Janssen Date : 2023-06-04 */ #version 3.8; global_settings{ assumed_gamma 1.0 } #default{ finish{ ambient 0.1 diffuse 0.9 }} #declare T_Pos = <0, 0, 0>; #declare A_F = 14; // Angle increment #declare Max_Items = 200; #declare Curr_Items = 0; #declare VXY_Arr = array[Max_Items]; // Pos stack for xy-plane #declare AZZ_Arr = array[Max_Items]; // Angle stack for xy-plane //build rules #declare BuildRules = dictionary; #macro F (T_Pos, AngleZZ) //#local T_Pos = <0, 0, 0>; // #end #declare BuildRules["F"] = 70; //chr(70) = F #declare BuildRules["X"] = asc("X"); // 88 #debug concat( "X = ", str(asc("X"), 0, 0), "\n") #macro MoveRight (T_Pos) //#local T_Pos = ; //#declare VXY_Arr[Curr_Items] = T_Pos; //#declare AZZ_Arr[Curr_Items] = AngleZZ; //#declare Curr_Items = Curr_Items + 1; #end #macro YawR (AngleZZ) #local AngleZZ = 0; AngleZZ + (tau/A_F) #end #declare BuildRules["+"] = 43; #macro YawL (AngleZZ) #local AngleZZ = 0; AngleZZ - (tau/A_F) #end #declare BuildRules["-"] = 45; #macro Turn (AngleZZ) #local AngleZZ = 0; AngleZZ - (tau/2) #end #declare BuildRules["|"] = 124; // the following macros are needed for branching #macro Push (T_Pos, AngleZZ, Curr_Items) #declare VXY_Arr[Curr_Items] = T_Pos; #declare AZZ_Arr[Curr_Items] = AngleZZ; #declare Curr_Items = Curr_Items + 1; #end #declare BuildRules["["] = 91; #macro Pop (T_Pos, AngleZZ, Curr_Items) #declare Curr_Items = Curr_Items - 1; #declare T_Pos = VXY_Arr[Curr_Items]; #declare AngleZZ = AZZ_Arr[Curr_Items]; #end #declare BuildRules["]"] = 93; // // I left Ingo's brilliant rewrite macro untouched #macro Ltransform (Axiom, Rules, Iterations) #local Result = Axiom; #for (i, 1, Iterations) #local NewResult = ""; #local N = strlen (Result); #local j = 1; #while (j <= N) #local CurrentSymbol = substr (Result, j, 1); #ifdef (Rules[CurrentSymbol]) #local NewResult = concat (NewResult, Rules[CurrentSymbol]); #else #local NewResult = concat (NewResult, CurrentSymbol); #end // end ifdef #local j = j + 1; #end // end while #local Result = NewResult; //#debug concat(Result, "\n") #end // end for i Result #end #macro Lvertices(Lstr) #local T_Pos = <0, 0, 0>; // #local AngleZZ = 0; #local Curr_Items = 0; #declare Return = array; //{}; #declare Return [0] = ; #//for (i, 0, strlen (Lstr)-1) #for (i, 1, strlen (Lstr)) // jr #local CurrentSymbol = substr (Lstr, i, 1); #ifdef (BuildRules [CurrentSymbol]) #switch (BuildRules [CurrentSymbol]) #case (70) #local T_Pos = F (T_Pos, AngleZZ); #break #case (43) #local AngleZZ = YawR (AngleZZ); #break #case (45) #local AngleZZ = YawL (AngleZZ); #break #case (124) #local AngleZZ = Turn (AngleZZ); #break #case (91) #local Curr_Items = Push (T_Pos, AngleZZ, Curr_Items); #break #case (93) #local Curr_Items = Pop (T_Pos, AngleZZ, Curr_Items); #break #case (88) #local T_Pos = MoveRight (T_Pos); #break #else #break #end // end switch //#local InArr = Return[dimension_size(Return, 1)-1]; #local InArr = Return [dimension_size (Return, 1)-1]; #if (T_Pos.x != InArr.x | T_Pos.y != InArr.y | T_Pos.z != InArr.z) #declare Return [dimension_size (Return, 1)] = ; #end // end if #end // end ifdef #end // end for i #declare Vertices = Return; Vertices #end /* #declare Axiom = "FFFFX"; #declare Rules = dictionary { ["X"] : "F[-FX][+FX]", // ["Y"] : "FX-Y" } */ #declare Axiom = "FFFFX"; #declare Rules = dictionary { ["X"] : "F[-X|][+F|]", // ["Y"] : "FX-Y" } #declare Iterations = 50; #declare Lstr = Ltransform (Axiom, Rules, Iterations); #declare Vertices = Lvertices (Lstr); #ifdef (Vertices) #debug "OK \n" #else #debug "Undefined! \n" #end #for (i, 0, dimension_size (Vertices, 1)-2) // <== here Povray complains cylinder {Vertices [i], Vertices [i+1], 0.1 texture {pigment {rgb 1}} translate <-25, -5, 0> rotate <0, 0, 0> } #end camera{ location <0, 0, -30> look_at <0, 0, 0> angle 120 right x*image_width/image_height } light_source { <3000, 3000, -3000> color rgb 1 } //---%<------%<------%<---