/* -------------------------- Entry: 0025 WWW: http://www.generation5.org Title: Old fashioned L-Systems Author: Paolo Gibellini This is a basic L-System parser and printer: There is a macro which parses L-System language string, useful to generate old fashioned but interesting bidimensional fractals. I hope you can enjoy with ;-) ---------------------------*/ /* * @file lsystems.pov * @desc A basic L-System parser and printer * Here is a macro which parses L-System language string, useful to generate * old fashioned but interesting bidimensional fractals * @ver 1.0.1 * @date 16/04/2004 * @ref An Introduction to Lindenmayer Systems (http://www.cogs.susx.ac.uk/users/gabro/lsys/lsys.html) * @ref Samples of LSE (http://www.generation5.org) * @todo A better documentation and a better parser... ;-) */ #version 3.5; #include "colors.inc" global_settings { assumed_gamma 1.0 } // ---------------------------------------- // ToDo: adaptive camera ------------------ camera { location <0, 0, -20> look_at <2, 0, 0> } light_source { <0, 0, 0> color rgb <1, 1, 1> translate <-5, 10, -20> } // ---------------------------------------- // Background ----------------------------- plane { z, 400 pigment { color rgb <1,0.65,0.0> } } // ---------------------------------------- // Textures ------------------------------- #declare t_orange = texture { pigment{color rgb<1,0.25,0>} finish {ambient 0.15 diffuse 0.85 phong 1} } #declare t_white = texture { pigment{color rgb<1,1,1>} finish {ambient 0.15 diffuse 0.85 phong 1} } #declare t_tex_orange=texture{ checker texture{t_orange} texture{t_white} scale <0.1, 0.1, 0.1> } #declare t_tex_blue=texture{ pigment{ color rgb<0.2,0.5,0.8>} } #declare t_tex_green=texture{ pigment{ color rgb<0.2,0.8,0.5>} } #declare t_tex_asteroid=texture { pigment { bozo color_map { [ 0.0 rgbft <0.51, 0.51, 0.51, 0.0, 0.0> ] [ 1.0 rgbft <1.0, 1.0, 1.0, 0.0, 0.0> ] } turbulence 0.6 omega 0.8 lambda 3.0 ramp_wave } normal { bumps , 1.0 scale <0.75, 0.75, 1.0> turbulence 0.6 octaves 5 omega 0.65 lambda 3.0 frequency 0.0 ramp_wave } finish { ambient 0.15 specular 0.2 } } // ---------------------------------------- // Defaults ------------------------------- #declare t_coord=<0,0,0>; // Current coordinates #declare t_angle=0; // Current angle #declare t_lpath=1; // Path length #declare t_dir=6; // Rotation=360/directions #declare t_level=0; // current level #declare l_dim=0.05; // Line diameter #declare r_init="="; // Rule init #declare r_end=";"; // Rule end #declare n_rules=0; // Num rules #declare n_max_rules=100; // Max num rules #declare n_max_stacks=200; // Max stacks number #declare a_coord_stack=array[n_max_stacks]; // Coordinates Stack #declare a_angle_stack=array[n_max_stacks]; // Angles stack #declare n_curr_stack=0; #declare t_rules=""; // Final rule // ---------------------------------------- // Drawing functions ---------------------- // Line from... to..., diameter, texture, translation, rotation #macro lineto(from, to, dim, tex, trasla, ruota) union { cylinder {from, to, dim} sphere {from, dim} sphere {to, dim} texture{tex} translate trasla rotate ruota } #end // Moves turtle #macro turtle_move(regola, tex, trasla, ruota) #local n_rules=strlen(regola); #local n_currule=0; #while(n_currule0) str_replace(axiom_applicato,a_rules_k[i],a_rules_v[i]) #local axiom_applicato=str_replaced; #end #local i=i+1; #end #local i_s=i_s+1; #end // Updates final rules #declare t_rules=axiom_applicato; #end // ---------------------------------------- // Tools ---------------------------------- // Init the turtle #macro init_turtle(axiom, rules, directions, n_step, tex, trasla, ruota) #declare t_dir=directions; // By now... #declare t_lpath=t_lpath/n_step; fill_array_rules(rules) parse_string(axiom, a_rules_k, a_rules_v, n_step) turtle_move(t_rules, tex, trasla, ruota) #end // ---------------------------------------- // Sample Output -------------------------- init_turtle("X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X", "X=[F+F+F+F[---X-Y]+++++F++++++++F-F-F-F];Y=[F+F+F+F[---Y]+++++F++++++++F-F-F-F];", 24, 2, t_tex_blue, <-2,0,-8>, <30,40,0>) #declare l_dim=0.02; init_turtle("F+F+F", "F=F-F++F-F;", 5, 4, t_tex_orange, <-1.2,-1,-19>, 0) #declare t_coord=<0,0,0>; #declare t_angle=0; #declare t_lpath=2; #declare l_dim=0.2; init_turtle("F++F++F++F++F", "F=F++F++F|F-F++F;", 10, 2, t_tex_asteroid, <2,3,-8>, <10,-40,0>) #declare t_coord=<0,0,0>; #declare t_angle=0; #declare t_lpath=1; #declare l_dim=0.1; init_turtle("X", "X=F[+X]F[-X]+X;F=FF;", 20, 6, t_tex_green, <-15,0,0>, <0,0,50>) // ----------------------------------------