POV-Ray : Newsgroups : povray.newusers : How to use self defined functions as patterns? Server Time: 16 Dec 2018 23:56:12 GMT
  How to use self defined functions as patterns? (Message 1 to 10 of 10)  
From: rastertastic
Subject: How to use self defined functions as patterns?
Date: 2 Apr 2018 13:05:01
Message: <web.5ac22a4ac20ce887122abcd30@news.povray.org>
Just started using Povray really don't understand almost anything about it yet,
so maybe I should peruse the manual more but instead I will ask a question with
the risk of not making sense.

Section "3.4.7.1.12 Function Pattern" explains that it's possible to define a
function and use that as a pattern. The manual gives an example:
#declare Foo = function { x + y + z}.

Ok but that function doesn't give values in the range [0,1], for example in the
positive x,y plane Foo just keeps growing.

So if I want to use that function as the pattern type for, say, a color map, can
I specify such ever larger values in the color map.

For example could I use a color map like

color_map {
  [0  color Red]
  [10  color Green]
  [20  color Blue]
  [30  color Pink]
  }

But rendering the following doesn't produce what I might expect if that is
supposed to work:

plane { <0, 1, 0>, 0
    texture {
      pigment { function { Foo(x, y, z) }

               color_map {
                 [0  color Red]
                 [10  color Green]
                 [20  color Blue]
                 [30  color Pink]
               }
      }
    }

}

So basically I'm asking clarification on how to use such self-defined functions
like  x + y + z  as patterns with, say, color maps.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: How to use self defined functions as patterns?
Date: 2 Apr 2018 16:25:00
Message: <web.5ac2592d1863261df773ca290@news.povray.org>
"rastertastic" <nomail@nomail> wrote:
> For example could I use a color map like
>
> color_map {
>   [0  color Red]
>   [10  color Green]
>   [20  color Blue]
>   [30  color Pink]
>   }
>
> But rendering the following doesn't produce what I might expect if that is
> supposed to work:
>
> plane { <0, 1, 0>, 0
>     texture {
>       pigment { function { Foo(x, y, z) }
>
>                color_map {
>                  [0  color Red]
>                  [10  color Green]
>                  [20  color Blue]
>                  [30  color Pink]
>                }
>       }
>     }
>
> }
>
> So basically I'm asking clarification on how to use such self-defined functions
> like  x + y + z  as patterns with, say, color maps.

Why don't you use a valid color map with range 0 to 1? - Then you will very
quickly see what happens and find the answer yourself.


Post a reply to this message

From: clipka
Subject: Re: How to use self defined functions as patterns?
Date: 2 Apr 2018 18:28:12
Message: <5ac2763c$1@news.povray.org>
Am 02.04.2018 um 15:04 schrieb rastertastic:

> Section "3.4.7.1.12 Function Pattern" explains that it's possible to define a
> function and use that as a pattern. The manual gives an example:
> #declare Foo = function { x + y + z}.
> 
> Ok but that function doesn't give values in the range [0,1], for example in the
> positive x,y plane Foo just keeps growing.

The function result is always "folded" into the [0..1] range; the exact
algorithm depends on the waveform (ramp_wave being the default).


Post a reply to this message

From: Stephen
Subject: Re: How to use self defined functions as patterns?
Date: 2 Apr 2018 18:39:23
Message: <5ac278db$1@news.povray.org>
On 02/04/2018 17:24, Thorsten Froehlich wrote:
> Why don't you use a valid color map with range 0 to 1? - Then you will very
> quickly see what happens and find the answer yourself.

Because the clock has ticked, the world has moves on a bit. RTFM has 
gone out of favour.
Hints and guidance are better teaching methods.


-- 

Regards
     Stephen


Post a reply to this message

From: rastertastic
Subject: Re: How to use self defined functions as patterns?
Date: 3 Apr 2018 00:40:00
Message: <web.5ac2cc851863261d122abcd30@news.povray.org>
Thanks for your answers. OK I should define such functions so that the image of
the function is in [0,1] for best/predictable results.

clipka:
> The function result is always "folded" into the [0..1] range; the exact
> algorithm depends on the waveform (ramp_wave being the default).

Ok thanks for that information, I was wondering how it decides what color to
give for values outside that range, to be honest I don't quite understand your
answer but it's enough for now.

The manual is a treasure trove I shall spend more time reading it.


Post a reply to this message

From: rastertastic
Subject: Re: How to use self defined functions as patterns?
Date: 3 Apr 2018 06:00:05
Message: <web.5ac317ca1863261d122abcd30@news.povray.org>
"rastertastic" <nomail@nomail> wrote:
> Thanks for your answers. OK I should define such functions so that the image of
> the function is in [0,1] for best/predictable results.
>

Just to add I understand that doing it that way is not always necessary since
the "repeating" pattern thanks to the "folding" clipka mentioned can produce
good results.


Post a reply to this message

From: Kenneth
Subject: Re: How to use self defined functions as patterns?
Date: 4 Apr 2018 00:55:00
Message: <web.5ac420fc1863261da47873e10@news.povray.org>
"rastertastic" <nomail@nomail> wrote:

>
> So basically I'm asking clarification on how to use such self-defined functions
> like  x + y + z  as patterns with, say, color maps.

Here's a simple example...

#declare Foo = function(x,y){2*x + 2*y}

box{<0,0,0>, <1,1,.01>
pigment {
  function {Foo(x,y)}
       sine_wave // otherwise, a default 'ramp' wave is used
       color_map{
              [0 rgb 0]
              [1 rgb 1]
              }
       }
       }

The interesting thing to note is that the resulting sine-wave-like appearance is
actually a sort of 'absolute' sine-wave-- in other words, instead of an expected
'peak and trough', the troughs have been turned into peaks as well. (That's the
visual result, anyway.) I don't yet know how to 'bias' the function or
color_map(?) to get a 'full' sine-wave-- or what looks like one, at least.

BTW, somewhere in the POV-Ray documentation, it states that when using a
function as a pigment or pigment pattern, the 'image' of the function is
actually just an infinitely thin slice, taken in the x/y plane (x from 0.0 to
1.0, y from 0.0 to 1.0). You can change the location of that slice, though:
                 #declare Foo = function(x,y){2*(x + 1.7) + 2*y}

This moves the slice by 1.7 units in x -- although +1.7 actually means -1.7,
strangely enough. Put another way, the imaginary 'camera' that's sampling the
slice has ITSELF moved +1.7 units in x. So the pattern appears to move -1.7
units.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: How to use self defined functions as patterns?
Date: 4 Apr 2018 12:05:01
Message: <web.5ac4bed81863261df773ca290@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> "rastertastic" <nomail@nomail> wrote:
>
> >
> > So basically I'm asking clarification on how to use such self-defined functions
> > like  x + y + z  as patterns with, say, color maps.
>
> Here's a simple example...
>
> #declare Foo = function(x,y){2*x + 2*y}
>
> box{<0,0,0>, <1,1,.01>
> pigment {
>   function {Foo(x,y)}
>        sine_wave // otherwise, a default 'ramp' wave is used
>        color_map{
>               [0 rgb 0]
>               [1 rgb 1]
>               }
>        }
>        }

This just discards the z position of the function.

> BTW, somewhere in the POV-Ray documentation, it states that when using a
> function as a pigment or pigment pattern, the 'image' of the function is
> actually just an infinitely thin slice, taken in the x/y plane (x from 0.0 to
> 1.0, y from 0.0 to 1.0). You can change the location of that slice, though:
>                  #declare Foo = function(x,y){2*(x + 1.7) + 2*y}

It does not say that, the pattern function is three dimensional, not two
dimensional. You are free to not use all three dimensions though.


Post a reply to this message

From: rastertastic
Subject: Re: How to use self defined functions as patterns?
Date: 4 Apr 2018 12:40:01
Message: <web.5ac4c7561863261d122abcd30@news.povray.org>
Thanks for mentioning "Waveforms" didn't know about that.

Thinking about these function patterns is actually surprisingly fun. Managed to
make a polkadot pattern by a function f(x,y,z)-->[0,1] that I think I can use as
a basis for a good a starry sky texture with a lot of control on the appearance
of the stars. I will post pictures in the next few weeks hopefully when I have
more time.


Post a reply to this message

From: Kenneth
Subject: Re: How to use self defined functions as patterns?
Date: 5 Apr 2018 04:10:01
Message: <web.5ac5a0a91863261da47873e10@news.povray.org>
"Thorsten Froehlich" <nomail@nomail> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:

> > BTW, somewhere in the POV-Ray documentation, it states that when using a
> > function as a pigment or pigment pattern, the 'image' of the function is
> > actually just an infinitely thin slice, taken in the x/y plane (x from 0.0 to
> > 1.0, y from 0.0 to 1.0). You can change the location of that slice, though:
> >                  #declare Foo = function(x,y){2*(x + 1.7) + 2*y}
>
> It does not say that, the pattern function is three dimensional, not two
> dimensional. You are free to not use all three dimensions though.

Hmm. I was probably thinking of a 'function image' instead--
     3.6.2.1.12.2 Function Image
"Note: Functions are evaluated on the x-y plane. This is different from the
pattern image type for the reason that it makes using uv functions easier"

"Width and Height specify the resolution of the resulting 'internal' bitmap
image. The image is taken from the square region <0,0,0>, <1,1,0>"

Sorry for the confusion. Yes, POV-ray's patterns are 3-dimensional. But the
example images in the docs (at  3.6.2.1.12 Function Pattern)  *appear* to be
only 2-dimensional there as well-- or rather, taken from what looks like a 2-D
'slice' ;-)


Post a reply to this message

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