POV-Ray : Newsgroups : povray.newusers : loop in function Server Time
5 Nov 2024 03:19:18 EST (-0500)
  loop in function (Message 1 to 6 of 6)  
From: Adrien Rebollo
Subject: loop in function
Date: 25 Aug 2002 13:11:06
Message: <3d690faa$1@news.povray.org>
Hello,

I would like to define a function with a while loop inside, like this :

#declare my_array = array[Imax] {
	function ...
} // array of functions

#declare my_function = function {
	#local res = 0;
	#local I = 0;
	#while (I < Imax)
		#local res = res + my_array[I](x,y,z);
		#local I = I + 1;
	#end
	res
}

but povray complains about x, y and z being vectors, not floats.

I know there is a sum(...) pattern which could achieve the same thing, but
I put a sum for the example, it could be whatever loop in a function,
which tries to use the x, y, z coordinates that fails.

Adrien Rebollo


Post a reply to this message

From: Christoph Hormann
Subject: Re: loop in function
Date: 25 Aug 2002 13:50:00
Message: <3D6918C8.6CC91DDA@gmx.de>
Adrien Rebollo wrote:
> 
> Hello,
> 
> I would like to define a function with a while loop inside, like this :
> 
> [...]
> 
> I know there is a sum(...) pattern which could achieve the same thing, but
> I put a sum for the example, it could be whatever loop in a function,
> which tries to use the x, y, z coordinates that fails.

You are mixing up the different levels in a POV-Script.  #declare/#local
work at parse time and not during rendering, therefore

#local res = res + my_array[I](x,y,z);

tries to assign a value to res while parsing and expects x, y and z to be
symbols for 1 unit vectors like elsewhere in a POV-Script.  

For how to use arrays of functions and loops in functions see the
'IC_Merge_Array()' macro in the IsoCSG include file.

Christoph

-- 
POV-Ray tutorials, IsoWood include,                 
TransSkin and more: http://www.tu-bs.de/~y0013390/  
Last updated 13 Aug. 2002 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Adrien Rebollo
Subject: Re: loop in function
Date: 25 Aug 2002 14:11:22
Message: <3d691dca@news.povray.org>
Thank you very much.

So, something like this would work :

#declare my_function = function {
        #local I = 0;
        #while (I < Imax)
                #if (I>0) + #end
                my_array[I](x,y,z)
        #end
}

Before you answered, I tried the sum pattern, and I have another error that 
I do not understand :

#declare my_function = function {
        sum (I, 0, Imax, my_array[I](x,y,z))
}

gives me
Parse Error: Expected 'numeric expression', undeclared identifier 'I' found 
instead

What is the trick ? (it is only curiosity, I will use your method anyway)

Adrien Rebollo

Christoph Hormann wrote:

> 
> 
> Adrien Rebollo wrote:
>> 
>> Hello,
>> 
>> I would like to define a function with a while loop inside, like this :
>> 
>> [...]
>> 
>> I know there is a sum(...) pattern which could achieve the same thing,
>> but I put a sum for the example, it could be whatever loop in a function,
>> which tries to use the x, y, z coordinates that fails.
> 
> You are mixing up the different levels in a POV-Script.  #declare/#local
> work at parse time and not during rendering, therefore
> 
> #local res = res + my_array[I](x,y,z);
> 
> tries to assign a value to res while parsing and expects x, y and z to be
> symbols for 1 unit vectors like elsewhere in a POV-Script.
> 
> For how to use arrays of functions and loops in functions see the
> 'IC_Merge_Array()' macro in the IsoCSG include file.
> 
> Christoph
>


Post a reply to this message

From: Warp
Subject: Re: loop in function
Date: 25 Aug 2002 18:27:26
Message: <3d6959cd@news.povray.org>
Adrien Rebollo <adr### [at] gmxfr> wrote:
> #declare my_function = function {
>         sum (I, 0, Imax, my_array[I](x,y,z))
> }

> gives me
> Parse Error: Expected 'numeric expression', undeclared identifier 'I' found 
> instead

  Well, it's exactly what the error message says: I has not been defined
anywhere, so POV-Ray can't know what do you mean by it.
  You have to #declare its value.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Adrien Rebollo
Subject: Re: loop in function
Date: 25 Aug 2002 18:44:14
Message: <3d695dbd@news.povray.org>
Warp wrote:

> Adrien Rebollo <adr### [at] gmxfr> wrote:
>> #declare my_function = function {
>>         sum (I, 0, Imax, my_array[I](x,y,z))
>> }
> 
>> gives me
>> Parse Error: Expected 'numeric expression', undeclared identifier 'I'
>> found instead
> 
>   Well, it's exactly what the error message says: I has not been defined
> anywhere, so POV-Ray can't know what do you mean by it.
>   You have to #declare its value.
> 

Then why does this work ?
#declare my_function = function {
        sum (I, 0, Imax, 2*I)
}

I have not #declared I either.


Post a reply to this message

From: Warp
Subject: Re: loop in function
Date: 25 Aug 2002 19:07:07
Message: <3d69631b@news.povray.org>
Adrien Rebollo <adr### [at] gmxfr> wrote:
> Then why does this work ?
> #declare my_function = function {
>         sum (I, 0, Imax, 2*I)
> }

  I get this:

File: ...  Line: 3
        sum (I, 0, Imax, 2*I)

} <----ERROR

Parse Error: Expected 'parameter identifier or floating-point constant identifier', }
found instead

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

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