POV-Ray : Newsgroups : povray.newusers : Problem with using rand : Re: Problem with using rand Server Time
30 Jun 2024 03:56:41 EDT (-0400)
  Re: Problem with using rand  
From: Bolek
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.