POV-Ray : Newsgroups : povray.newusers : Calling 'procedures' with variables? Server Time
5 Sep 2024 16:21:11 EDT (-0400)
  Calling 'procedures' with variables? (Message 1 to 6 of 6)  
From: Simon de Vet
Subject: Calling 'procedures' with variables?
Date: 29 Aug 2000 17:10:53
Message: <39AC2738.5D9668D1@istar.ca>
I've created a pigment type which depends on a variable, n. If I
#declare n before the pigment code, it runs correctly.

However, I would like to be able to call this pigment type many times,
with different values of n. I thought that I could simply remove the
#declare before the pigment code, and use the code like:

texture { #declare n=1
              PigmentName
            }
texture { #declare n=2
              PigmentName
            }

However, POV complains that n is undefined when it first encounters the
code.

How can I use the pigment code as a procedure, called with the variable?
I've tried #macro, but haven't gotton anything working.

Thanks!


Simon


Post a reply to this message

From: Chris Huff
Subject: Re: Calling 'procedures' with variables?
Date: 29 Aug 2000 17:33:41
Message: <chrishuff-C8E47D.16351429082000@news.povray.org>
In article <39AC2738.5D9668D1@istar.ca>, sde### [at] istarca wrote:

> I've created a pigment type which depends on a variable, n. If I
> #declare n before the pigment code, it runs correctly.
> 
> However, I would like to be able to call this pigment type many times,
> with different values of n. I thought that I could simply remove the
> #declare before the pigment code, and use the code like:

You aren't "calling a pigment type", you are creating a copy of a 
variable which has already been parsed.


> How can I use the pigment code as a procedure, called with the variable?
> I've tried #macro, but haven't gotton anything working.

The macro feature is what you want. Just wrap the pigment definition in 
a macro statement and use the parameters to specify your variables. What 
were you trying to do?

#macro Radial(Rays, ClrA, ClrB)
    pigment {radial
        frequency Rays
        color_map {
            [0 color ClrA]
            [1 color ClrB]
        }
    }
#end

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Simon de Vet
Subject: Re: Calling 'procedures' with variables?
Date: 29 Aug 2000 21:16:38
Message: <39AC60D1.D4A0E968@istar.ca>
Chris Huff wrote:

> #macro Radial(Rays, ClrA, ClrB)
>     pigment {radial
>         frequency Rays
>         color_map {
>             [0 color ClrA]
>             [1 color ClrB]
>         }
>     }
> #end

I'm using something nearly identical, but it is still not working.

My code is of the form:

#macro PigmentFunc (n)
    #declare Pigment = pigment { bla bla n bla bla }
#end

I then try to call it by using:

PigmentFunc (0.5)
texture {Pigment}


However, Pov still complains when it gets to the first line of the code which
contains the n variable, saying "numeric expression expected but undeclared
identifier 'n' found instead."

Am I missing something fundamental here? Would there be any benifit in my
posing the code?


Simon


Post a reply to this message

From: ryan constantine
Subject: Re: Calling 'procedures' with variables?
Date: 29 Aug 2000 22:58:42
Message: <39AC7863.E2C82923@yahoo.com>
some single letters have been taken over by megapov as reserved words. 
try making n a real word like my_n_variable to eliminate the possiblity
of conflict.

J Charter wrote:
> 
> >
> > >#macro PigmentFunc (n)
> >     #declare Pigment = pigment { bla bla n bla bla }
> > #end
> >
> >
> >
> > PigmentFunc (0.5)
> > texture {Pigment}
> >
> 
> I take it you tried:
> 
> n=0.5;
> PigmentFunc(n)


Post a reply to this message

From: Chris Huff
Subject: Re: Calling 'procedures' with variables?
Date: 30 Aug 2000 09:38:35
Message: <chrishuff-8621C7.08400930082000@news.povray.org>
In article <39AC60D1.D4A0E968@istar.ca>, sde### [at] istarca wrote:

> However, Pov still complains when it gets to the first line of the 
> code which contains the n variable, saying "numeric expression 
> expected but undeclared identifier 'n' found instead."

This sounds like a typo somewhere. Make sure you use an upper-case 
letter in all variables to avoid conflicts with keywords, and make sure 
you use the same variable name in the pigment as you used in the macro 
parameter list.


> Am I missing something fundamental here?

Try something more like this:

#macro PigmentFunc (n)
pigment { bla bla n bla bla }
#end

...

texture {PigmentFunc(0.5)}


You can also use the macro to declare a pigment, like this:

#declare MyPigment = PigmentFunc(0.35)


> Would there be any benifit in my posing the code?

It would help us to find what exactly is wrong with it, but you seem to 
be doing it in a round-about way, you might want to completely change 
the way you are doing it.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Mike Williams
Subject: Re: Calling 'procedures' with variables?
Date: 30 Aug 2000 15:35:59
Message: <izezRGATvRr5Ewzm@econym.demon.co.uk>
Wasn't it Simon de Vet who wrote:

>My code is of the form:
>
>#macro PigmentFunc (n)
>    #declare Pigment = pigment { bla bla n bla bla }
>#end
>
>I then try to call it by using:
>
>PigmentFunc (0.5)
>texture {Pigment}
>
>
>However, Pov still complains when it gets to the first line of the code which
>contains the n variable, saying "numeric expression expected but undeclared
>identifier 'n' found instead."
>
>Am I missing something fundamental here? Would there be any benifit in my
>posing the code?

The problem is somewhere else, in part of the code that you're not
describing. The syntax you describe above works perfectly for me, e.g.

#macro PigmentFunc (n)
  #declare Pigment = pigment{rgb <n,n,0>}
#end
  
PigmentFunc (0.2)  
sphere{-x,1
 texture{Pigment}
 }

PigmentFunc(0.5)  
sphere{0,1
 texture{Pigment}
 }

PigmentFunc(0.9)  
sphere{x,1
 texture{Pigment}
 }
  
Works perfectly, though it might have been simpler to code it more like
this:-

#macro PigFun (n)
  rgb <n,n,0>
#end

sphere {y,1 texture{pigment{PigFun(0.1)}}}
sphere {-y,1 texture{pigment{PigFun(0.9)}}}


Are you using the official POVRay, or MEGAPov? There can sometimes be
strange behaviour in MEGAPov in the following circumstances:

  If you declare a #macro inside a #while loop.

  If you declare one #macro inside another #macro declaration.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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