POV-Ray : Newsgroups : povray.general : Recursion re...uh..iterated? : Re: Recursion re...uh..iterated? Server Time
31 Jul 2024 10:23:35 EDT (-0400)
  Re: Recursion re...uh..iterated?  
From: Tim Attwood
Date: 2 Apr 2007 22:47:39
Message: <4611c04b$1@news.povray.org>
> Thanks, I really should have seen that.  The problem now is passing the
> correct values for position to the recursive calls.  The thing about LOGO
> is that it remembers the position and direction of the turtle at all 
> times,
> it will continue moving on a set vector unless you tell it otherwise. 
> POV,
> on the other hand, has to be told where to go and what to do once it gets
> there.


// Macros for treating POV-Ray like LOGO --  by Tim Attwood 4/2/2007
#declare PenSize = 0.025;
#declare PenColor = Yellow;
#declare PenStep = 0.1;
#declare PenState = on;
#declare PenDir = <0,0,1>;
#declare PenUp = <0,1,0>;
#declare PenLoc = <0,0,0>;
#macro Turtle() cone{PenLoc,PenSize*2,PenLoc+PenDir*PenStep*4,0
   pigment{color PenColor}} #end
#macro PU() #declare PenState = off; #end
#macro PD() #declare PenState = on; #end
#macro FD(a)
   #local b = PenLoc+PenDir*PenStep*a;
   #if (PenState = on)
      cylinder{PenLoc, b, PenSize pigment{color PenColor} }
      sphere{b,PenSize pigment{color PenColor}}
   #end
   #declare PenLoc = b;
#end
#macro BK(a)
   #local b = PenLoc-PenDir*PenStep*a;
   #if (PenState = on)
      cylinder{PenLoc,b,PenSize pigment{color PenColor}}
      sphere{b pigment{color PenColor}}
   #end
   #declare PenLoc = b;
#end
#macro LT(a) #declare PenDir = vaxis_rotate(PenDir,PenUp,-a); #end
#macro RT(a) #declare PenDir = vaxis_rotate(PenDir,PenUp,a); #end
#macro TiltUp(a)
   #local r = vnormalize(vcross(PenDir,PenUp));
   #declare PenDir = vaxis_rotate(PenDir,r,a);
   #declare PenUp = vaxis_rotate(PenUp,r,a);
#end
#macro TiltDown(a)
   #local r = vnormalize(vcross(PenDir,PenUp));
   #declare PenDir = vaxis_rotate(PenDir,r,-a);
   #declare PenUp = vaxis_rotate(PenUp,r,-a);
#end

// example
#macro Tree(a, stopat)
   #if (a > stopat)
      RT(30)
      FD(a)
      Tree( a/2, stopat)
      PU()
      BK(a)
      LT(60)
      PD()
      FD(a)
      Tree( a/2, stopat)
      PU()
      BK(a)
      RT(30)
      PD()
   #end
#end

PU()
TiltUp(90)
BK(10)
PD()
#declare PenColor = Brown;
FD(5)
#declare PenColor = Green;
Tree(10,0.5)
#declare PenColor = Yellow;
FD(4)
Turtle()


Post a reply to this message

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