# Perlin Noise

Another important way to simulate randomness is using Perlin noise generation. Perlin noise generation differs from random generation as it uses a “smooth” sequence of psuedo random numbers, where a singular value in a sequence depends on its predecessors. This is especially useful in creating natural phenomena such as clouds and the textures of materials like marble or wood.

For Perlin noise to work, it is defined in an infinite n-dimensional space with the co-ordinates bound to be between 0.0 and 0.1 and fixed to a semi random number. It is somewhat similar to an audio signal, working within octaves, which are combined to get the final result.

As you can see in the sketch below, the circle seems to “breathe” in and out as it grows and shrinks as although the value is random, it is based on the value that went before it.

```float time = 0.0;
float increment = 0.01;

void setup() {
size(200,200);
smooth();
}

void draw() {
background(255);

// Get a noise value at "time" and scale it according to the window's width.
float n = noise(time)*width;

// With each cycle, increment the " time "
time += increment;

// Draw the ellipse with size determined by Perlin noise
fill(0);
ellipse(width/2,height/2,n,n);
}```

In Processing Perlin noise can be used in 2 and 3 dimensions as well to create natural looking textures. Say for example you used Perlin noise to calculate brightness of pixels. The pixels would form clumps of brightness as each individual pixel’s brightness is determined by the brightness of pixels that are around it. Take for example the below sketch:

```float noiseVal;
float noiseScale=0.02;

void draw() {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width/2; x++) {
noiseDetail(3,0.5);
noiseVal = noise((mouseX+x) * noiseScale, (mouseY+y) * noiseScale);
stroke(noiseVal*255);
point(x,y);
noiseDetail(8,0.65);
noiseVal = noise((mouseX + x + width/2) * noiseScale,
(mouseY + y) * noiseScale);
stroke(noiseVal * 255);
point(x + width/2, y);
}
}
}```

Here the noiseDetail class is used to change the output of Perlin noise. The box on the left has less detail as it uses less octaves (3 as opposed to 8) and it also has a lower falloff value (0.5 compared to 0.65.) The falloff value is the impact each octave will have on the lower octave. At default it is 0.5.

This will be very useful is I want to recreate organic motion or patterns in the future and is often used in CGI as a low-cost way to create natural textures and structures.

Shiffman, D., 2012. The Nature of Code [online] Mountain View: Creative Commons.

Processing 2. 2014. noise(). Available: https://processing.org/reference/noise_.html. Last accessed 18.11.2014.

Processing 2. 2014. noiseDetail(). Available: https://processing.org/reference/noise_.html. Last accessed 18.11.2014.

Shiffman, D. 2008. CHAPTER 13: EXAMPLE 13-4: PERLIN NOISE. Available: http://www.learningprocessing.com/examples/chapter-13/example-13-4-perlin-noise/. Last accessed 18.11.2014.

LibbyOdaiDMD