POV-Ray : Newsgroups : povray.general : Hexagon pattern with 4 or 7 colors? : Re: Hexagon pattern with 4 or 7 colors? Server Time
24 Apr 2024 09:37:51 EDT (-0400)
  Re: Hexagon pattern with 4 or 7 colors?  
From: clipka
Date: 27 Apr 2018 09:56:20
Message: <5ae32c04$1@news.povray.org>
Am 27.04.2018 um 14:02 schrieb Bald Eagle:

> Is there a syntax by which I can do a function of a function?
> 
> I'm looking to something along the lines of:
> 
> #declare A = function (b, d) {b+d}
> #declare Q = function (A(b,d), k) {A*k}
> 
> but POV-Ray doesn't calculate the result of A to be used as a parameter of Q.
> It complains that it's expecting a parameter, but found a function instead.
> 
> I'm thinking there ought to be a way to G(F(x)).

That depends on what you are trying to achieve.

For G(F(x)), how about

    #declare F = function(x) { x+1 }
    #declare G = function(y) { y*y }
    #declare Foo = G(F(4711)); // ((4711)+1)^2

Or, if you want to "hide" F(x) inside G(x), how about

    #declare F = function(x) { x+1 }
    #declare G = function(x) { F(x)*F(x) }
    #declare Foo = G(4711); // ((4711)+1)^2


As a side note to the latter case, note that F(x) will be invoked twice
per invocation of G(x); to avoid this, in such cases I tend to use a mix
of the above:

    #declare F = function(x) { x^2 }
    #declare G_ = function(y) { y*y }
    #declare G = function(x) { G_(F(x)) }


Post a reply to this message

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