• Main Page
  • Files
  • File List
  • File Members

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

Go to the documentation of this file.
00001 #include "MusimatChapter9.h"
00002 MusimatChapter9Section(C091704d) {
00003         Print("*** Voss's Method ***");
00004         /*****************************************************************************
00005          
00006          Voss's Method
00007          
00008          Martin Gardner (1978) reported a fractal noise generator attributed to Voss. A 
00009          set of random variables xk are summed on each sample n, and the result is output. The random vari-
00010          ables are updated at different rates. If , then the k th variable is assigned a new random 
00011          number Us. The index k ranges from 0 to N - 1. So x0 is randomized every sample, x1 is randomized 
00012          every other sample, x2 is randomized every fourth sample, and so on, until finally xN-1 is only 
00013          randomized every  samples.  We can code this method as follows:
00014          *****************************************************************************/
00015         para1(); // Step into this function to continue.
00016 }
00017 
00018 Real VossFracRand( Integer n, RealList L ) {
00019         Real sum = 0.0;
00020         Integer N = Length( L );
00021         For(Integer k = 0; k < N; k = k + 1) {
00022                 If (Mod(n, Integer(Pow(2, k))) == 0) {
00023                         L[k] = Random(-1.0, 1.0);
00024                 }
00025                 sum = sum + L[ k ];
00026         }
00027         Return(sum);
00028 }
00029 
00030 Static Void para1() {
00031         /*****************************************************************************
00032          The following creates and prints a list of 128 fractal noise samples over four octaves:
00033          *****************************************************************************/
00034         
00035         RealList L(Random(), Random(), Random(), Random());
00036         RealList R;
00037         
00038         For (Integer n = 0; n < 128; n = n + 1) {
00039                 R[n] = VossFracRand(n, L);
00040         }
00041         
00042         Print("*** Voss' Fractal Method ***");
00043         Print(R);
00044         
00045         /*****************************************************************************
00046          Figure 9.32 shows how this noise is constructed by this method. Each function changes at a rate 
00047          twice as fast as the previous function, and the functions are summed. Random values in the rapidly 
00048          changing functions have only local influence, whereas values in the slowly changing functions extend 
00049          their influence over many samples of the summed result, giving the result a fractal characteristic.
00050          *****************************************************************************/
00051 }
00052 
00054 /* $Revision: 1.3 $ $Date: 2006/09/05 08:02:46 $ $Author: dgl $ $Name:  $ $Id: C091704d.cpp,v 1.3 2006/09/05 08:02:46 dgl Exp $ */
00055 // The Musimat Tutorial © 2006 Gareth Loy
00056 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00057 // and published exclusively by The MIT Press.
00058 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00059 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00060 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00061 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00062 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00063 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00064 // The Musimat website:                 http://www.musimat.com/
00065 // This program is released under the terms of the GNU General Public License
00066 // available here:                      http://www.gnu.org/licenses/gpl.txt
00067 

Generated on Fri Nov 26 2010 16:18:24 for Musimat Chapter 9 Code Examples by  doxygen 1.7.2