![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Adrien Rebollo <adr### [at] gmx fr> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> Adrien Rebollo <adr### [at] gmx fr> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Adrien Rebollo <adr### [at] gmx fr> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |