POV-Ray : Newsgroups : povray.general : recursion problem : Re: recursion problem Server Time
4 Aug 2024 14:23:48 EDT (-0400)
  Re: recursion problem  
From:
Date: 16 Apr 2003 20:27:07
Message: <3e9df4db$1@news.povray.org>
//  Hi Lenx,
//
//  here is a complete scene with the recursion you wanted; I hope
//  you can understand how it works. Simply render this whole text with
//
//     +W800 +H600 -F +D +A0.1
//
//  in the command line. (5 seconds at 1 GHz)
//
//     Sputnik



#macro RecursiveBox (Layers, MidX, BottomY, MidZ, SideLength)

  // draw a box
  box { <MidX-SideLength/2, BottomY           , MidZ-SideLength/2>,
        <MidX+SideLength/2, BottomY+SideLength, MidZ+SideLength/2> }

  #if (Layers>1) // if there are more boxes to be stacked ...

    // ... then calculate some auxiliary values and ...
    #local NewBY = BottomY + SideLength;
    #local NewSL = SideLength/3; // also try 4, 2.5, 2.2, 10
    #local Offset = SideLength/2-NewSL/2; // also try "+" instead of "-"
    // ... put four cube-stacks at the corners of the box
    RecursiveBox (Layers-1, MidX-Offset, NewBY, MidZ-Offset, NewSL)
    RecursiveBox (Layers-1, MidX-Offset, NewBY, MidZ+Offset, NewSL)
    RecursiveBox (Layers-1, MidX+Offset, NewBY, MidZ-Offset, NewSL)
    RecursiveBox (Layers-1, MidX+Offset, NewBY, MidZ+Offset, NewSL)

    #end//if

  #end//macro


// activate the RecursiveBox-macro
union { RecursiveBox (6,  0,-11,0,  9)
  texture { pigment { color rgb <1, .7, .3> } }
  }


//light and camera
light_source { <-10, 20, -7>, 1 }
camera { location <-3, 8, -10> look_at 0 }


Post a reply to this message

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