POV-Ray : Newsgroups : povray.general : Passing macro as parameter Server Time
20 Nov 2024 06:32:31 EST (-0500)
  Passing macro as parameter (Message 1 to 7 of 7)  
From: Kilgore Trout
Subject: Passing macro as parameter
Date: 28 Oct 2001 08:49:15
Message: <3bdc0cdb$1@news.povray.org>
Hi,

Is there any way that I can pass the name of a macro as a paramter to
another macro?  For example, I'm defining one macro, F(X, Z) as a function
and I would like to pass this as one of the parameters to another macro.
But when I put Macro1(F), it tells me it's expecting a '('.

Thanks,
Kev


Post a reply to this message

From: JRG
Subject: Re: Passing macro as parameter
Date: 28 Oct 2001 08:56:34
Message: <3bdc0e92@news.povray.org>
First you define your two macros, then you can use one as a parameter for
the other one:

example (not tested)

#macro SQUARE (A)
A*A
#end

#macro INCR (B)
B+1
#end

#declare c=SQUARE ( INCR (2) ); // it should give you (2+1)^2=9


Post a reply to this message

From: Kilgore Trout
Subject: Re: Passing macro as parameter
Date: 28 Oct 2001 09:09:52
Message: <3bdc11b0$1@news.povray.org>
That's sort of different from what I'm tring to do.  I'm trying to make a
macro that can make a graph of surfaces defined by Y = F(X, Z), and I want
to pass F(X, Z) as a parameter to the macro.  But not just one value of F, I
want to be able to pass the function F, so I can call it several times
inside of the macro.  If this isn't clear, then I can post my code so you
can see what I have so far and what I'm trying to get.  Right now I am
declaring F outisde of the graph macro, but this is no good because I might
want to use two different F's in one scene.

Thanks,
Kev

"JRG" <jrg### [at] hotmailcom> wrote in message
news:3bdc0e92@news.povray.org...
> First you define your two macros, then you can use one as a parameter for
> the other one:
>
> example (not tested)
>
> #macro SQUARE (A)
> A*A
> #end
>
> #macro INCR (B)
> B+1
> #end
>
> #declare c=SQUARE ( INCR (2) ); // it should give you (2+1)^2=9
>
>


Post a reply to this message

From: JRG
Subject: Re: Passing macro as parameter
Date: 28 Oct 2001 09:29:42
Message: <3bdc1656@news.povray.org>
Hmm, let's see if I've understood you:
you have a macro called F (X,Z) defined as follows (I guess):
F (X,Z)

*expression with X and Z*

#end

Then you have another macro you want to pass F to it as a parameter (but you
don't want it to be F(X0,Y0) where X0 and Y0 are predefined values).
Then I guess you want to evaluate F inside the second macro.

Are you using POV 3.5? If that's the case why don't you simply define the
function inside the second macro?
i.e:

#macro Macro1()
#declare F=function (X,Z) { *expression with X and Z*}

and then you can evalute F inside the macro.

--
Jonathan.

"Kilgore Trout" <lou### [at] hotmailcom> ha scritto nel messaggio
news:3bdc11b0$1@news.povray.org...
> That's sort of different from what I'm tring to do.  I'm trying to make a
> macro that can make a graph of surfaces defined by Y = F(X, Z), and I want
> to pass F(X, Z) as a parameter to the macro.  But not just one value of F,
I
> want to be able to pass the function F, so I can call it several times
> inside of the macro.  If this isn't clear, then I can post my code so you
> can see what I have so far and what I'm trying to get.  Right now I am
> declaring F outisde of the graph macro, but this is no good because I
might
> want to use two different F's in one scene.
>
> Thanks,
> Kev
>
> "JRG" <jrg### [at] hotmailcom> wrote in message
> news:3bdc0e92@news.povray.org...
> > First you define your two macros, then you can use one as a parameter
for
> > the other one:
> >
> > example (not tested)
> >
> > #macro SQUARE (A)
> > A*A
> > #end
> >
> > #macro INCR (B)
> > B+1
> > #end
> >
> > #declare c=SQUARE ( INCR (2) ); // it should give you (2+1)^2=9
> >
> >
>
>


Post a reply to this message

From: Kilgore Trout
Subject: Re: Passing macro as parameter
Date: 28 Oct 2001 09:46:34
Message: <3bdc1a4a$1@news.povray.org>
I am using 3.1 still.  I will try what you suggested with 3.5.

Thanks!
Kevin

"JRG" <jrg### [at] hotmailcom> wrote in message
news:3bdc1656@news.povray.org...
> Hmm, let's see if I've understood you:
> you have a macro called F (X,Z) defined as follows (I guess):
> F (X,Z)
>
> *expression with X and Z*
>
> #end
>
> Then you have another macro you want to pass F to it as a parameter (but
you
> don't want it to be F(X0,Y0) where X0 and Y0 are predefined values).
> Then I guess you want to evaluate F inside the second macro.
>
> Are you using POV 3.5? If that's the case why don't you simply define the
> function inside the second macro?
> i.e:
>
> #macro Macro1()
> #declare F=function (X,Z) { *expression with X and Z*}
>
> and then you can evalute F inside the macro.
>
> --
> Jonathan.
>
> "Kilgore Trout" <lou### [at] hotmailcom> ha scritto nel messaggio
> news:3bdc11b0$1@news.povray.org...
> > That's sort of different from what I'm tring to do.  I'm trying to make
a
> > macro that can make a graph of surfaces defined by Y = F(X, Z), and I
want
> > to pass F(X, Z) as a parameter to the macro.  But not just one value of
F,
> I
> > want to be able to pass the function F, so I can call it several times
> > inside of the macro.  If this isn't clear, then I can post my code so
you
> > can see what I have so far and what I'm trying to get.  Right now I am
> > declaring F outisde of the graph macro, but this is no good because I
> might
> > want to use two different F's in one scene.
> >
> > Thanks,
> > Kev
> >
> > "JRG" <jrg### [at] hotmailcom> wrote in message
> > news:3bdc0e92@news.povray.org...
> > > First you define your two macros, then you can use one as a parameter
> for
> > > the other one:
> > >
> > > example (not tested)
> > >
> > > #macro SQUARE (A)
> > > A*A
> > > #end
> > >
> > > #macro INCR (B)
> > > B+1
> > > #end
> > >
> > > #declare c=SQUARE ( INCR (2) ); // it should give you (2+1)^2=9
> > >
> > >
> >
> >
>
>


Post a reply to this message

From: Slime
Subject: Re: Passing macro as parameter
Date: 28 Oct 2001 14:00:37
Message: <3bdc55d5$1@news.povray.org>
You could also have them pass the name of the macro as a string, and then
use that evalString function in strings.inc (that's not exactly what it's
called, but it's something like that).

- Slime
[ http://www.slimeland.com/ ]
[ http://www.slimeland.com/images/ ]

"Kilgore Trout" <lou### [at] hotmailcom> wrote in message
news:3bdc1a4a$1@news.povray.org...
> I am using 3.1 still.  I will try what you suggested with 3.5.
>
> Thanks!
> Kevin
>
> "JRG" <jrg### [at] hotmailcom> wrote in message
> news:3bdc1656@news.povray.org...
> > Hmm, let's see if I've understood you:
> > you have a macro called F (X,Z) defined as follows (I guess):
> > F (X,Z)
> >
> > *expression with X and Z*
> >
> > #end
> >
> > Then you have another macro you want to pass F to it as a parameter (but
> you
> > don't want it to be F(X0,Y0) where X0 and Y0 are predefined values).
> > Then I guess you want to evaluate F inside the second macro.
> >
> > Are you using POV 3.5? If that's the case why don't you simply define
the
> > function inside the second macro?
> > i.e:
> >
> > #macro Macro1()
> > #declare F=function (X,Z) { *expression with X and Z*}
> >
> > and then you can evalute F inside the macro.
> >
> > --
> > Jonathan.
> >
> > "Kilgore Trout" <lou### [at] hotmailcom> ha scritto nel messaggio
> > news:3bdc11b0$1@news.povray.org...
> > > That's sort of different from what I'm tring to do.  I'm trying to
make
> a
> > > macro that can make a graph of surfaces defined by Y = F(X, Z), and I
> want
> > > to pass F(X, Z) as a parameter to the macro.  But not just one value
of
> F,
> > I
> > > want to be able to pass the function F, so I can call it several times
> > > inside of the macro.  If this isn't clear, then I can post my code so
> you
> > > can see what I have so far and what I'm trying to get.  Right now I am
> > > declaring F outisde of the graph macro, but this is no good because I
> > might
> > > want to use two different F's in one scene.
> > >
> > > Thanks,
> > > Kev
> > >
> > > "JRG" <jrg### [at] hotmailcom> wrote in message
> > > news:3bdc0e92@news.povray.org...
> > > > First you define your two macros, then you can use one as a
parameter
> > for
> > > > the other one:
> > > >
> > > > example (not tested)
> > > >
> > > > #macro SQUARE (A)
> > > > A*A
> > > > #end
> > > >
> > > > #macro INCR (B)
> > > > B+1
> > > > #end
> > > >
> > > > #declare c=SQUARE ( INCR (2) ); // it should give you (2+1)^2=9
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Passing macro as parameter
Date: 28 Oct 2001 19:32:42
Message: <3BDCA387.B7B95B1@hotmail.com>
Kilgore Trout wrote:
> 
> That's sort of different from what I'm tring to do.  I'm trying to make a
> macro that can make a graph of surfaces defined by Y = F(X, Z), and I want
> to pass F(X, Z) as a parameter to the macro.  But not just one value of F, I
> want to be able to pass the function F, so I can call it several times
> inside of the macro.
>...

Kilgore,
if you've downloded POV-Ray v3.5.beta by now,
(as JRG suggested) then maybe my example code
below will be useful for you. It shows how to
pass user declared functions to macros as
parameters.

You may also wan't to have a look at isosurfaces.
They are very useful for graphing in 3D.

Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// By Tor Olav Kristensen
// Email: tor### [at] hotmailcom
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#version 3.5;

#include "colors.inc"
#include "golds.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#macro FunctionPlot(Fn, p1, p2, nn, Radius)

  #local dX = (p2 - p1).x/nn;
  #local dZ = (p2 - p1).z/nn;
  #local X = p1.x;
  #while (X < p2.x)
    #local Z = p1.z;
    #while (Z < p2.z)
      #local Y = Fn(X, 0, Z);
      sphere { <X, Y, Z>, Radius }
      #local Z = Z + dZ;
    #end // while
    #local X = X + dX;
  #end // while

#end // macro FunctionPlot

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#declare SombreroFn =
function(x, y, z) { 10*sin(sqrt(x^2 + z^2))/(sqrt(x^2 + z^2) + 1) }

#declare pA = -35*<1, 0, 1>;
#declare pB =  35*<1, 0, 1>;

union {
  FunctionPlot(function { SombreroFn(x, y, z) }, pA, pB, 200, 0.4)
  texture { T_Gold_2B }
}

/* // This code will produce a somewhat disturbed "sombrero"
#declare BozoFn =
function { pattern { bozo scale 4 } }

#declare MixedFn =
function(x, y, z) { SombreroFn(x, 0, z) - 2*BozoFn(x, 0, z) }

union {
  FunctionPlot(function { MixedFn(x, 0, z) }, pA, pB, 200, 0.4)
  texture { T_Gold_2B }
}
*/

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

sky_sphere { pigment { color Blue/2 } }

light_source { < 5,  4, -1>*10 color White shadowless }

camera {
  location <2, 5, -7>*2
  look_at <0, -4, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =


Post a reply to this message

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