POV-Ray : Newsgroups : povray.general : Trouble parsing recursive macro : Re: Trouble parsing recursive macro Server Time
31 Jul 2024 08:31:41 EDT (-0400)
  Re: Trouble parsing recursive macro  
From: barton
Date: 28 Jul 2007 21:00:01
Message: <web.46abe59553db5e6e071738a0@news.povray.org>
Ok; I figured it out...

check out http://loudsl01-253-100-25.iglou.com/~tiger/pov_images/cube2.png
for the results...

here's the code:

#macro Cube(X,Y,Z,E,L)

  #local Side = E * 0.80;
  #if ( L = 0)
        box { <X,Y,Z>, <X+Side,Y+Side,Z+Side>
                //pigment{color <R,G,B> }
        }
  #end // if recusion is false

  #if (L > 0)
    # local New_L = L - 1;
    # local New_E = Side / 10;
    # local i = 0;
    # local j = 0;
    # local k = 0;

    #while(i < 10)
        #while(j < 10)
                #while(k < 10)
                        #if( i = 0 | j = 0 | k = 0 | i = 9 | j = 9 | k = 9)
                                Cube(
                                        X+i*New_E,
                                        Y+j*New_E,
                                        Z+k*New_E,
                                        New_E, New_L
                                        )
                        #else
                                Cube(
                                        X+i*New_E,
                                        Y+j*New_E,
                                        Z+k*New_E,
                                        New_E, New_L - 1
                                        )
                        #end
                        #declare k = k+1;
                #end // Xhile k
                #declare k = 0;
                #declare j = j+1;
        #end // while j
        #declare j = 0;
        #declare i = i+1;
    #end // while i
  #end // if recursion is true
#end // macro Cube

#declare cube_radius = 3.9;

union {
  Cube(-cube_radius,0,-15,10,2)

  pigment { color rgb <1,0,0> }
}

light_source { <2,20,-10> color rgb <1,1,1> }
light_source { <2,10,-20> color rgb <1,1,1> }

background { color rgb <0, 0, 0> }

// Cube is 10 units wide... sub cubes

camera {
        right x
        location <0,3*cube_radius,-25>
        look_at  <0,0,-3.5>
}

What I did was to reduce the recursion level by 2 for the middle cubes ...
so the middle isn't empty, it's just filled with larger cubes that parse
more easily.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.