POV-Ray : Newsgroups : povray.animations : Random Scale : Re: Random Scale Server Time
28 Jul 2024 18:26:00 EDT (-0400)
  Re: Random Scale  
From: Ken
Date: 17 Mar 1999 08:30:41
Message: <36EFADD2.ECA370CA@pacbell.net>
Inexistencia-Design, Dec. P. Eventos Lda wrote:
> 
> Hello!
> I need to animate a cylinder by random scaling it up and down in y axis but
> a only want to scale from 0.9 to 1.1. How can I get a random number and get
> sure that falls between 0.9 and 1.1.
> I've tried with rand(seed(clock)) but can't get there.
> 
> Sergio

  This pair of macros will yield a random-number that varies smoothly
 over time. To use these macros, first #declare an array of four scalars
 and pass it to SmoothSeed( ). The macro will use the array to hold the
 seed( ) values for the four random-number sequences derived from the
 clock variable. Sequence is used to select the sequence to be used for
 generating the random numbers.

 Once SmoothSeed( ) is called, SmoothRand( ) will return a random number
 from 0 to 1. Subsequent calls to the macro within an animation frame will
 vary independently from each other, but the values themselves will vary
 smoothly from frame to frame.

           //example scene code

           #declare MyArray=array[4] {0,0,0,0}

           SmoothSeed(MyArray,0)

           sphere { y*(10+10*SmoothRand(MyArray)),1
             pigment { MyPigment }
           }

When animated, this will give a sphere that rises and falls randomly.
  
 Code: 
           #macro SmoothSeed(Array,Seq)
             #declare Array[0]= seed(floor(clock-1)+Seq);
             #declare Array[1]= seed(floor(clock)+Seq);
             #declare Array[2]= seed(floor(clock+1)+Seq);
             #declare Array[3]= seed(floor(clock+2)+Seq);
           #end

           #macro SmoothRand(Array)
             #local t_T=clock-floor(clock);
             #local t_R0=rand(Array[0]);
             #local t_R1=rand(Array[1]);
             #local t_R2=rand(Array[2]);
             #local t_R3=rand(Array[3]);
             #local t_C0=t_R1;
             #local t_C1=(t_R2-t_R0)*.5;
             #local t_C2=t_R0 - 2.5*t_R1 +2*t_R2-.5*t_R3;
             #local t_C3=-.5*t_R0 +1.5*t_R1 -1.5*t_R2 +.5*t_R3;
             (((((t_C3*t_T+t_C2)*t_T+t_C1)*t_T+t_C0)*.8)+.1)
           #end


-- 
Ken Tyler

mailto://tylereng@pacbell.net


Post a reply to this message

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