208 Learning Processing
Processing has a built-in implementation of the Perlin noise algorithm with the function noise( ) . e
noise( ) function takes one, two, or three arguments (referring to the “ space ” in which noise is computed:
one, two, or three dimensions). is chapter will look at one-dimensional noise only. Visit the Processing
web site for further information about two-dimensional and three-dimensional noise.
One-dimensional Perlin noise produces as a linear sequence of values over time. For example:
0.364, 0.363, 0.363, 0.364, 0.365
Note how the numbers move up or down randomly, but stay close to the value of their predecessor. Now,
in order to get these numbers out of Processing , we have to do two things: (1) call the function noise( ) , and
(2) pass in as an argument the current “ time. ” We would typically start at time t 0 and therefore call the
function like so: “ noise(t); ”
float t = 0.0;
float noisevalue = noise(t); // Noise at time 0
We can also take the above code and run it looping in draw( ) .
float t = 0.0;
void draw() {
float noisevalue = noise(t);
println(noisevalue);
}
e above code results in the same value printed over and over. is is because we are asking for the
result of the noise( ) function at the same point in “ time ” —0.0—over and over. If we increment the “ time ”
variable t, however, we will get a diff erent result.
float t = 0.0;
void draw() {
float noisevalue = noise(t);
println(noisevalue);
t + = 0.01;
}
Noise Detail
If you visit the Processing.org noise reference, you will fi nd that noise is calculated over several
“ octaves. ” You can change the number of octaves and their relative importance by calling
the noiseDetail( ) function. is, in turn, can change how the noise function behaves.
See http://processing.org/reference/noiseDetail_.html.
You can read more about how noise works from Ken Perlin himself:
http://www.noisemachine.com/talk1/.
Time moves forward!
Output:
0.28515625
0.28515625
0.28515625
0.28515625
Output:
0.12609221
0.12697512
0.12972163
0.13423012
0.1403218