POV-Ray : Newsgroups : povray.newusers : Problem with using rand Server Time
1 Nov 2024 00:26:28 EDT (-0400)
  Problem with using rand (Message 1 to 3 of 3)  
From: lucas
Subject: Problem with using rand
Date: 16 Oct 2011 10:30:00
Message: <web.4e9aea04ca006560bc426c6c0@news.povray.org>
Hello,

I declared a few functions. I need to use a random generator in one of them.
Accprding to documentation (http://www.povray.org/documentation/view/3.6.1/228/)
I thought that I can use function rand() as any other float function, but I
encountered a problem. I can declare a function like below:

#declare SinFn = function(R) { Ampl*sin(R)/(R + Damp)}

And this works.
When I want to add a rand function for example like below:

#declare SinFn = function(R) { Ampl*rand(seed(90))*sin(R)/(R + Damp)}

I got an error: "Parse Error: Expected 'function identifier', } found instead".
I am a newbie and I don't get it. Why can't I use those functions like others
listed in documentation (sin or cos for example)? What I am doing wrong? Below
you can find a part of my code. My goal is to make this surface look as it was
creased.


#declare Ampl = 5;
#declare Freq = 1.5;
#declare Damp = 0;

#declare SquashFn = function(T, S) { select(S, -0.5, 0.5)*(tanh(abs(S)*T) - 1) }

#declare SinFn = function(R) { Ampl*sin(R)/(R + Damp)}

#declare Fn = function(x, z) { SinFn(Freq*f_r(x, 0, z))}



#declare folia = isosurface {
  function {
    SquashFn(y - Fn(x, z), 10)
  }
  open
  threshold -0.5
  max_gradient 10
  contained_by {
    sphere{
        <0,0,0>, 3.7
    }
  }
  pigment { color rgbt<0.7,0.7,0.7,0.2> }
  rotate<180,0,0>
  translate<0, 4, 0>
  scale<0.5,0.5,0.5>
}


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Problem with using rand
Date: 16 Oct 2011 10:46:24
Message: <4e9aee40$1@news.povray.org>
On 16.10.11 16:28, lucas wrote:
> Hello,
>
> I declared a few functions. I need to use a random generator in one of them.
> Accprding to documentation (http://www.povray.org/documentation/view/3.6.1/228/)
> I thought that I can use function rand() as any other float function, but I
> encountered a problem. I can declare a function like below:

You need to look at the documentation for user-defined functions at 
http://www.povray.org/documentation/view/3.6.1/231/ . Some SDL functions 
cannot be used in user-defined functions. In your particular case, the best 
alternative is a noise function, which provides a 3D randomness that 
probably meets your needs.

	Thorsten


Post a reply to this message

From: Bolek
Subject: Re: Problem with using rand
Date: 23 Oct 2011 12:00:01
Message: <web.4ea438f5af11e0ac3fb4713c0@news.povray.org>
"lucas" <lucas> wrote:
> Hello,
>
> I declared a few functions. I need to use a random generator in one of them.
> Accprding to documentation (http://www.povray.org/documentation/view/3.6.1/228/)
> I thought that I can use function rand() as any other float function, but I
> encountered a problem. I can declare a function like below:
>
> #declare SinFn = function(R) { Ampl*sin(R)/(R + Damp)}
>
> And this works.
> When I want to add a rand function for example like below:
>
> #declare SinFn = function(R) { Ampl*rand(seed(90))*sin(R)/(R + Damp)}
>
> I got an error: "Parse Error: Expected 'function identifier', } found instead".
> I am a newbie and I don't get it. Why can't I use those functions like others
> listed in documentation (sin or cos for example)? What I am doing wrong? Below
> you can find a part of my code. My goal is to make this surface look as it was
> creased.
>
>
> #declare Ampl = 5;
> #declare Freq = 1.5;
> #declare Damp = 0;
>
> #declare SquashFn = function(T, S) { select(S, -0.5, 0.5)*(tanh(abs(S)*T) - 1) }
>
> #declare SinFn = function(R) { Ampl*sin(R)/(R + Damp)}
>
> #declare Fn = function(x, z) { SinFn(Freq*f_r(x, 0, z))}
>
>
>
> #declare folia = isosurface {
>   function {
>     SquashFn(y - Fn(x, z), 10)
>   }
>   open
>   threshold -0.5
>   max_gradient 10
>   contained_by {
>     sphere{
>         <0,0,0>, 3.7
>     }
>   }
>   pigment { color rgbt<0.7,0.7,0.7,0.2> }
>   rotate<180,0,0>
>   translate<0, 4, 0>
>   scale<0.5,0.5,0.5>
> }

I'm probably too late with this but I defined macros to do a similar task.
        #declare R1 = seed(0);
        #declare R2 = seed(37);
        #declare XYVariation = 0.015;
        #declare AngleVariation = 1;

        #macro XYMiss()
               (2*rand(R1)-1)*XYVariation
        #end

        #macro AngleMiss()
               (2*rand(R2)-1)*AngleVariation
        #end

I then use the macros as follows:

               rotate<0,0,AngleMiss()>
               translate <XYMiss(),XYMiss(),0>

This works for me.


Post a reply to this message

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