POV-Ray : Newsgroups : povray.general : Explanation of recursive macros. : Re: Explanation of recursive macros. Server Time
8 Aug 2024 22:11:28 EDT (-0400)
  Re: Explanation of recursive macros.  
From: BigCeef
Date: 12 Sep 2000 21:08:16
Message: <39bed380@news.povray.org>
Okay, I'm beginning to understand this. The line that says #local M=L-1; is
actually a loop, yes? I've only used while() loops before, so I didn't get
this at first.

I'm finding it hard to get my head round Recurs(M) being INSIDE Recurs(L).

Also, your code generated the following warning, which I've been unable to
remedy.

memory macro: 22: warning : Should have at least 2 objects in csg.
Degenerate CSG bounding box (not used!)

Well, there are more than 2 objects in the union. Huh?

--------
//my revised code (just experimenting..output object is a mess of cones)

#version 3.1
camera{location  -z*4  direction 1.5*z  right     4/3*x  look_at  0}

light_source{<-1,1,-1>*100 rgb 1}

#declare Scaler=0.75;

#macro Recurs(L)
union{

#if (L>0)
    #local M=L-1;
    //#local Scaler=0.75;
    #local Seedy=seed(M);
    cone {0,0.1,y,0.1*Scaler}
    sphere {0,0.12 pigment {rgb<1,.3,0>}}
    object{Recurs(M) rotate z*120  scale <Scaler,Scaler/1.1,Scaler>
translate y}
    object{Recurs(M) rotate -z*120  scale <Scaler,Scaler/1.1,Scaler>
translate y}
    object{Recurs(M) rotate -z*0  scale <Scaler,Scaler/1.1,Scaler> translate
y}
rotate <rand(Seedy)*20,rand(Seedy)*360,rand(Seedy)*20> rotate <-10,0,-10>
#end
}

#end


//----------------------------------------------------
object{Recurs(7) scale 0.5 translate -y*.5 pigment{rgb 1}}


Post a reply to this message

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