﻿ Noise Functions
HOME Mathematics Computer Science
Noise Functions
Prerequisites
Show All
Hide All
Heightmaps
Show/Hide
﻿
Introduction
• Heightmaps are a way of representing a 3D surface as a 2D image.
• Each pixel in the 2D image corresponds to a specific point on the 3D surface.
• The brightness of the pixel determines the height of the point:
• A dark pixel is a low point
• A bright pixel is a high point
Image rendered in SketchUp
Code
```from PIL import Image

im = Image.new("L", (256, 256))

for x in range(256):
for y in range(256):
pix[x,y] = 256 - abs(x - 128) - abs(y - 128)

im.save("test.png", "PNG")
im.show()
```

Noise Functions
﻿
Random Values
We can generate random values using a pseudorandom number generator:
Example
 X 1 2 3 4 ... rand(X) 28 21 96 96 ...
Visualization
Code
```import random

randX = [random.randint(0, 100) for x in range(0, 50)]
print(randX)
```
Noise
Many areas of procedural generation require random values, but the randomness needs to look more organic:
Visualization
This is the job of a noise function. It produces random data, but the data has an underlying organic nature.
Higher Dimensions
• The above examples were in one dimension
• X is an array of numbers, for each number in X there is a corresponding value.
• However it is often useful to generate noise for 2 or more dimensions:

Heightmap

3D Terrain

Image rendered in SketchUp
• In the above example a random value is assigned to each (x, y) coordinate pair:
• 2D noise functions are often used to generate terrains in which the height values are the result of the noise function applied to each point.
• (x, y, z) = (x, y, noise(x, y))
• Noise functions can be extended into 3 or more dimensions:
• For example, a 3D noise function could be used for modelling gas. The random value at each 3D point could describe its density.
• 3D noise functions can also be used to animate 2D noise functions:
• A 3D array of data is produced and then cut into a series of 2D slices.
• You can then convert each slice into an individual frame of an animation.
• This can then be used for when you need 2D noise that changes over time, such as when animating the formation of clouds.
Related