POV-Ray : Newsgroups : povray.general : how to call multiple instances of a macro? : Re: how to call multiple instances of a macro? Server Time
30 Jul 2024 12:25:38 EDT (-0400)
  Re: how to call multiple instances of a macro?  
From: CShake
Date: 11 Mar 2009 16:30:46
Message: <49b81f76@news.povray.org>
Christian Froeschlin wrote:
> Christian Froeschlin wrote:
> 
>> [GDS|Entropy] wrote:
>>
>>> Would one be able to pass signs (+ - / *)
>>
>> no
> 
> Of course, no one prevents you from passing a function
> which performs the operation, whatever your reasons:
> 
>   #declare op_add  = function(x,y){x+y}
>   #declare op_sub  = function(x,y){x-y}
>   #declare op_mult = function(x,y){x*y}
>   #declare op_div  = function(x,y){x/y}
>   #declare op_avg  = function(x,y){0.5*op_add(x,y)}
> 
>   #macro ConcatFunc(OP,F1,F2)
>     function {OP(F1(x,y,z),F2(x,y,z))}
>   #end
> 
>   #declare f_combined = ConcatFunc(op_avg, f_bozo, f_agate)
> 
> Just think clearly about what you wish to achieve before doing it ;)

I have a related question - is it possible to pass the name of a macro 
as a parameter in another macro? I notice in the documentation that it 
doesn't say that RVALUE can be a function, though apparently it can 
based on your example, so can it be other things as well?

cshake

example:
#macro lamp1(location,pointat,brightness)
   light_source{...}
#end
...
#macro lamp24(location,pointat,brightness)
   light_source{...}
#end

#macro stringOfLights(Lamp,Center,Brightness)
   #local i=1;
   #while(i<10)
     Lamp(Center+i*x,Center+i*x+<point_vector>,Brightness)
     #local i=i+1;
   #end
#end

stringOfLights("lamp1",<1,2,3>,10)


Post a reply to this message

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