POV-Ray : Newsgroups : povray.general : HELP Using macro to visualise mathematical functions : Re: HELP Using macro to visualise mathematical functions Server Time
2 Aug 2024 08:11:59 EDT (-0400)
  Re: HELP Using macro to visualise mathematical functions  
From: Mike Williams
Date: 30 Nov 2004 13:49:07
Message: <uCYjsDAMCMrBFwjX@econym.demon.co.uk>
Wasn't it The Ugly who wrote:
>I would like to make a macro that visualises mathematical functions.
>Something like this would be nice.
>
>
>
>
>#macro MyFunc(Length,Formula)
>
>#local N=0;
>
>#while (N<=Length)
>
>sphere { 0, 0.02
>        pigment { rgb <N,0,N*-1+1> }
>        translate <N,Formula,0>
>        }
>
>#local N=N+0.1;
>
>#end
>
>#end


You've just made one tiny syntax error in that macro. 
Here's a complete scene that works.

camera {location  <5,0,-20> look_at <5,0,0> angle 30}
background {rgb 1}
light_source {<-30, 100, -30> color rgb 1}

#macro MyFunc(Length,Formula)
 #local N=0;
 #while (N<=Length)
  sphere { 0, 0.02
    pigment { rgb <N,0,N*-1+1> }
    translate <N,Formula(N),0>          // I changed this line
  }
  #local N=N+0.1;
 #end
#end

// Call it with length and one-dimensional function
MyFunc(10, function(n){sin(n)} )

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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