|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Why does this not work? It complains that I need to initialize X and Y before I
call them in the macro Fracp, but since I am passing them as parameters to the
function Gridd this would obviously be inappropriate. I have also tried changing
the macro into another function, but that doesn't work either.
#declare thick=0.05;
#macro Fracp(A)
A-floor(A)
#end
#declare Gridd = function( X, Y ) {
#if ( Fracp(X)<thick | Fracp(X)>(1-thick) | Fracp(Y)<thick | Fracp(Y)>(1-thick)
)
1
#else
0
#end
}
Cheers,
H.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Am 20.12.2010 07:49, schrieb TheBigH:
> Why does this not work? It complains that I need to initialize X and Y before I
> call them in the macro Fracp, but since I am passing them as parameters to the
> function Gridd this would obviously be inappropriate. I have also tried changing
> the macro into another function, but that doesn't work either.
>
>
> #declare thick=0.05;
> #macro Fracp(A)
> A-floor(A)
> #end
> #declare Gridd = function( X, Y ) {
> #if ( Fracp(X)<thick | Fracp(X)>(1-thick) | Fracp(Y)<thick | Fracp(Y)>(1-thick)
> )
> 1
> #else
> 0
> #end
> }
Note that "#" statements are always evaluated at parsing time, even when
used in a function. Therefore, "#if" statements cannot be used to
perform tests inside functions at run-time.
You will need to use the "select" function to have the condition
evaluated each time the function is called.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
clipka <ano### [at] anonymousorg> wrote:
> Am 20.12.2010 07:49, schrieb TheBigH:
> > Why does this not work? It complains that I need to initialize X and Y before I
> > call them in the macro Fracp, but since I am passing them as parameters to the
> > function Gridd this would obviously be inappropriate. I have also tried changing
> > the macro into another function, but that doesn't work either.
> >
> >
> > #declare thick=0.05;
> > #macro Fracp(A)
> > A-floor(A)
> > #end
> > #declare Gridd = function( X, Y ) {
> > #if ( Fracp(X)<thick | Fracp(X)>(1-thick) | Fracp(Y)<thick | Fracp(Y)>(1-thick)
> > )
> > 1
> > #else
> > 0
> > #end
> > }
>
> Note that "#" statements are always evaluated at parsing time, even when
> used in a function. Therefore, "#if" statements cannot be used to
> perform tests inside functions at run-time.
>
> You will need to use the "select" function to have the condition
> evaluated each time the function is called.
I see, thank for the heads up. I'm beginning to see that many things that are
straightforward and logical in other programming languages require awkward
contortions in POV-ray. Of course I could just do something like
#declare Gridd = function(X,Y) {
(( X-floor(X)<thick )|(X-floor(X)>(1-thick))|( Y-floor(Y)<thick
)|(Y-floor(Y)>(1-thick)))
}
because the function I want only takes the values zero and one, but if I ever
want other values, or more than two different values, I need proper selection of
cases. And I would definitely have preferred a nice orderly succession of #ifs
to the horror of nested selects. Oh well.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"TheBigH" <nomail@nomail> wrote:
> I see, thank for the heads up. I'm beginning to see that many things that are
> straightforward and logical in other programming languages require awkward
> contortions in POV-ray. Of course I could just do something like
>
> #declare Gridd = function(X,Y) {
> (( X-floor(X)<thick )|(X-floor(X)>(1-thick))|( Y-floor(Y)<thick
> )|(Y-floor(Y)>(1-thick)))
> }
>
> because the function I want only takes the values zero and one, but if I ever
> want other values, or more than two different values, I need proper selection of
> cases. And I would definitely have preferred a nice orderly succession of #ifs
> to the horror of nested selects. Oh well.
The real question you should ask yourself is why you need a function at all and
if another macro won't suffice. The primary use of functions is for objects that
require runtime evaluation, i.e. isosurfaces, and a binary selection is not the
best solution. Another user for functions is in user-defined patterns, where
your problem mightbbe much better solved using a map, i.e. a color_map.
Thorsten
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
And a couple of additional trivial thoughts...
(1) Expressions of the type "x * (x > someDangNumber)" can be used in
functions--might something like this be useful?
(2) I notice that "X" and "Y" are capitalized--might this be a problem?
--Sherry Shaw
--
#macro T(E,N)sphere{x,.4rotate z*E*60translate y*N pigment{wrinkles scale
.3}finish{ambient 1}}#end#local I=0;#while(I<5)T(I,1)T(1-I,-1)#local I=I+
1;#end camera{location-5*z}plane{z,37 pigment{granite color_map{[.7rgb 0]
[1rgb 1]}}finish{ambient 2}}// TenMoons
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Sherry Shaw <ten### [at] aolcom> wrote:
> (2) I notice that "X" and "Y" are capitalized--might this be a problem?
You can name function parameters as you like.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp <war### [at] tagpovrayorg> wrote:
> Sherry Shaw <ten### [at] aolcom> wrote:
> > (2) I notice that "X" and "Y" are capitalized--might this be a problem?
>
> You can name function parameters as you like.
Are you sure ?
I do not have access to POV-Ray right now to check, but IIRC one (or more) is
problematic to use; like "t".
--
Tor Olav
http://subcube.com
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tor Olav Kristensen <tor### [at] toberemovedgmailcom> wrote:
> Warp <war### [at] tagpovrayorg> wrote:
> > Sherry Shaw <ten### [at] aolcom> wrote:
> > > (2) I notice that "X" and "Y" are capitalized--might this be a problem?
> >
> > You can name function parameters as you like.
> Are you sure ?
> I do not have access to POV-Ray right now to check, but IIRC one (or more) is
> problematic to use; like "t".
Ok, 't' is special for some reason. But eg. 'T' is fine.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
>
> You can name function parameters as you like.
>
Just wondered if perhaps he was using the function in a context where x
and y might be expected (as in an isosurface, for example), as opposed
to explicitly passing two parameters.
--Sherry Shaw
--
#macro T(E,N)sphere{x,.4rotate z*E*60translate y*N pigment{wrinkles scale
.3}finish{ambient 1}}#end#local I=0;#while(I<5)T(I,1)T(1-I,-1)#local I=I+
1;#end camera{location-5*z}plane{z,37 pigment{granite color_map{[.7rgb 0]
[1rgb 1]}}finish{ambient 2}}// TenMoons
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |