/* parsestr.pov * this simple scene demonstrates the use of the 'Parse_String' macro * to build Object Identifiers dynamically, at runtime. * * command-line: * povray Declare=OBJ=N ... * ^^^^^^^^^^^^^ * * where N is one of the following: * 1 - box, 2 - cylinder, 3 - ovus, 4 - sphere, 5 - torus. * * date: 19.3.2016. * author: jr . * license: Creative Commons CC0. * thanks to 'Bald Eagle' who provided the inspiration (motivation!). */ #version 3.7; global_settings { assumed_gamma 1.0 } #include "colors.inc" // Parse_String. #include "strings.inc" light_source { <10,10,-10> White } camera { location <1.5,1.5,-2.5> right x*image_width/image_height look_at <0,0,0> } // objects to select. #declare the_box = box {<-.5,-.5,-.5>, <.5,.5,.5> texture {pigment {Blue}}}; #declare the_cylinder = cylinder {<0,-.5,0>, <0,.5,0>, .65 texture {pigment {Blue}}}; #declare the_ovus = ovus {.65, .35 texture {pigment {Blue}}}; #declare the_sphere = sphere {<0,0,0>, 1 texture {pigment {Blue}}}; #declare the_torus = torus {1, .35 texture {pigment {Blue}}}; #declare the_help = "box (1), cylinder (2), ovus (3), sphere (4), or torus (5)"; #declare the_objs = array[5]; #declare the_objs[0] = "box"; #declare the_objs[1] = "cylinder"; #declare the_objs[2] = "ovus"; #declare the_objs[3] = "sphere"; #declare the_objs[4] = "torus"; #declare the_prefix = "the_"; // verify OBJ has been declared and is in range. #ifndef(OBJ) #error concat("missing argument OBJ\ninvoke ('Declare'ing) one of: ", the_help, ".\n") #elseif(1 > OBJ | 5 < OBJ) #error concat("bad argument OBJ\nexpected one of: ", the_help, ", got: ", str(OBJ,0,0),".\n") #end // confirm selection. #debug concat("you chose the '", the_objs[OBJ-1], "', now rendering object '", the_prefix, the_objs[OBJ-1] ,"'.\n") // use macro. object { Parse_String( concat(the_prefix, the_objs[OBJ-1]) ) }