Skip to main content

A fast Perlin noise generation library!

Project description

perlinNoise

A Perlin noise generation library implemented in Go

Build

To build a shared library accessible from Python

go build -o perlin_noise.so -buildmode=c-shared main/src

You made need to include the following build flags

CGO_ENABLED=1

As well as operating and platform specific flags. For example on an Apple Silicon Mac,

GOOS=darwin GOARCH=arm64

Tests and Examples

To run perlinNoise and generate example simplex and Perlin noise images,

go run main/src

Simplex Noise
Perlin Noise
Or, you can run the Python test script that serves as a demo of how to integrate perlinNoise into your project. Ensure you have the required dependencies:

python3 --version
pip3 --version
pip3 install -r requirements.txt

To run the script,

python3 example.py

Output

perlinNoise currently outputs a matrix of noise of which the values range from 0.0 to 1.0.

Interface and Parameters

Perlin noise can be generated using the generatePerlinNoise function. See test.py for an example of how to load and access the library in Python.

Parameter Type Description
resultPtr *float32 Pointer to the output matrix (faked dimensionality)[1]
width uint32 Width of resultant matrix.
height uint32 Height of resultant matrix.
persistence float32 Intensity falloff coefficient of subsequent noise layers.
numLayers uint32 Number of simplex noise layers to use.
roughness float32 Frequency increase coefficient for subsequent noise layers.
baseRoughness float32 Initial frequency for noise
strength float32 Scalar multiplier for noise values
randomSeed float32 Define the random seed to be used

Controlling the noise's behaviour

Behaviour of the noise can be changed by changing parameters to the generatePerlinNoise interface. Settings include width and height to determine the dimensions of the resulting matrix. baseRoughness and roughness to control the frequency and frequency falloff. persistence to change the impact of subsequent layers (low value results in a "softer" look). numLayers controls how many layers of noise will be used (more layers results in more complex, structured noise). strength is a simple scalar multiplier to the matrix (control intensity of noise). Lastly, randomSeed can be changed to change the seed of the noise (perlinNoise is deterministic when randomSeed is known).

Faked Dimensionality

For reduced complexity of the interface between the compiled library and the user, two-dimensionality is faked for the output matrix. Instead of an actual [width, height] matrix, a vector of width * height elements will be used. Nonetheless, we can index what would be at [x, y] if we were using an actual matrix by indexing [x * width + y] in our vector, thus faking the dimensions. The result for the use case of perlinNoise is identical functionality with a simpler interface.


It is easy to restore the actual matrix. Here's an example with NumPy, and without NumPy in Python. Assuming that output_vector is the resultant vector returned by generatePerlinNoise with which was called with width=N and height=M.

# Example using NumPy
import numpy as np
noise_vector: np.ndarray = np.array(output_vector, 'f')
noise_matrix: np.ndarray = noise_vector.reshape(N, M)

# Example without NumPy
noise_matrix = [[], []]
for x in range(N):
    for y in range(M):
        noise_matrix[x, y] = output_vector[x * N + y]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_perlin_noise-0.1.0.tar.gz (48.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Fast_Perlin_Noise-0.1.0-py3-none-any.whl (1.5 MB view details)

Uploaded Python 3

File details

Details for the file fast_perlin_noise-0.1.0.tar.gz.

File metadata

  • Download URL: fast_perlin_noise-0.1.0.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for fast_perlin_noise-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efdd92bccf5201d7d43b95e2f497a26c65a271aa280e41344cd51e9b9f732c86
MD5 fdccdad432b4d29f1d32dded7555cbf9
BLAKE2b-256 4524b11ae5c56556d039520e2d84dfe5980a50b759c3d2bd99c6f38d67ef2264

See more details on using hashes here.

File details

Details for the file Fast_Perlin_Noise-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for Fast_Perlin_Noise-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d5d79d348105a794d2ef8d659e5073744f2e03042ccd60538cc5d44969241fb
MD5 2e4fa9168a9f78caa6b5d2546f0f497b
BLAKE2b-256 c099111c5c64055413e8389b20a7b21fbe34990a51ae0d7890838f8c95035b57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page