Functions

/Users/garethloy/Musimathics/Musimat1.2/MusimatChapter9/C091704d.cpp File Reference

#include "MusimatChapter9.h"

Go to the source code of this file.

Functions

 MusimatChapter9Section (C091704d)
Real VossFracRand (Integer n, RealList L)
Static Void para1 ()

Function Documentation

MusimatChapter9Section ( C091704d   )

Definition at line 2 of file C091704d.cpp.

References para1().

                                 {
        Print("*** Voss's Method ***");
        /*****************************************************************************
         
         Voss's Method
         
         Martin Gardner (1978) reported a fractal noise generator attributed to Voss. A 
         set of random variables xk are summed on each sample n, and the result is output. The random vari-
         ables are updated at different rates. If , then the k th variable is assigned a new random 
         number Us. The index k ranges from 0 to N - 1. So x0 is randomized every sample, x1 is randomized 
         every other sample, x2 is randomized every fourth sample, and so on, until finally xN-1 is only 
         randomized every  samples.  We can code this method as follows:
         *****************************************************************************/
        para1(); // Step into this function to continue.
}
Static Void para1 (  )

Definition at line 30 of file C091704d.cpp.

References n(), and VossFracRand().

                    {
        /*****************************************************************************
         The following creates and prints a list of 128 fractal noise samples over four octaves:
         *****************************************************************************/
        
        RealList L(Random(), Random(), Random(), Random());
        RealList R;
        
        For (Integer n = 0; n < 128; n = n + 1) {
                R[n] = VossFracRand(n, L);
        }
        
        Print("*** Voss' Fractal Method ***");
        Print(R);
        
        /*****************************************************************************
         Figure 9.32 shows how this noise is constructed by this method. Each function changes at a rate 
         twice as fast as the previous function, and the functions are summed. Random values in the rapidly 
         changing functions have only local influence, whereas values in the slowly changing functions extend 
         their influence over many samples of the summed result, giving the result a fractal characteristic.
         *****************************************************************************/
}
Real VossFracRand ( Integer  n,
RealList  L 
)

Definition at line 18 of file C091704d.cpp.

References sum().

                                           {
        Real sum = 0.0;
        Integer N = Length( L );
        For(Integer k = 0; k < N; k = k + 1) {
                If (Mod(n, Integer(Pow(2, k))) == 0) {
                        L[k] = Random(-1.0, 1.0);
                }
                sum = sum + L[ k ];
        }
        Return(sum);
}