Skip to main content

OpenSimplex n-dimensional gradient noise function.

Project description

OpenSimplex Noise

build-status pypi-version

    OpenSimplex noise is an n-dimensional gradient noise function that was
    developed in order to overcome the patent-related issues surrounding
    Simplex noise, while continuing to also avoid the visually-significant
    directional artifacts characteristic of Perlin noise.

This is merely a python port of Kurt Spencer's original code (released to the public domain) and neatly wrapped up in a package.

Status

The main branch contains the latest stable v0.4.

This version has been tested with Python 3.7, 3.8, 3.9 on Linux, MacOS and Windows.

Updates:

  • Adds a hard dependency on 'Numpy', for array optimizations aimed at heavier workloads.
  • Adds optional dependency on 'Numba', for further speed optimizations using caching.
  • General refactor and cleanup of the library and tests.
  • Breaking changes: API function names has been modified.

Usage

Installation:

    pip install opensimplex

Basic usage:

    >>> import opensimplex
    >>> opensimplex.seed(1234)
    >>> n = opensimplex.noise2(x=10, y=10)
    >>> print(n)
    0.580279369186297

For more advanced examples, see the files in the tests and example directory.

Available functions:

opensimplex.seed(seed)

Seeds the underlying permutation array (which produces different outputs), using a 64-bit seed number.

opensimplex.noise2(x, y)

Generate 2D OpenSimplex noise from X,Y coordinates.

opensimplex.noise2array(x, y)

Same as noise2, but works with numpy arrays for better performance.

opensimplex.noise3(x, y, z)

Generate 3D OpenSimplex noise from X,Y,Z coordinates.

opensimplex.noise3array(x, y, z)

Same as noise3, but works with numpy arrays for better performance.

opensimplex.noise4(x, y, z, w)

Generate 4D OpenSimplex noise from X,Y,Z,W coordinates.

opensimplex.noise4array(x, y, z, w)

Same as noise4, but works with numpy arrays for better performance.

Running tests and benchmarks:

    virtualenv venv
    source venv/bin/activate
    make deps

and then simply run the tests:

    make test

or the benchmark:

    make benchmark

FAQ

  • Is this relevantly different enough to avoid any real trouble with the original patent?

    If you read the patent claims:

    Claim #1 talks about the hardware-implementation-optimized gradient generator. Most software implementations of Simplex Noise don't use this anyway, and OpenSimplex Noise certainly doesn't.

    Claim #2(&3&4) talk about using (x',y',z')=(x+s,y+s,z+s) where s=(x+y+z)/3 to transform the input (render space) coordinate onto a simplical grid, with the intention to make all of the "scissor-simplices" approximately regular. OpenSimplex Noise (in 3D) uses s=-(x+y+z)/6 to transform the input point to a point on the Simplectic honeycomb lattice so that the simplices bounding the (hyper)cubes at (0,0,..,0) and (1,1,...,1) work out to be regular. It then mathematically works out that s=(x+y+z)/3 is needed for the inverse transform, but that's performing a different (and opposite) function.

    Claim #5(&6) are specific to the scissor-simplex lattice. Simplex Noise divides the (squashed) n-dimensional (hyper)cube into n! simplices based on ordered edge traversals, whereas OpenSimplex Noise divides the (stretched) n-dimensional (hyper)cube into n polytopes (simplices, rectified simplices, birectified simplices, etc.) based on the separation (hyper)planes at integer values of (x'+y'+z'+...).

    Another interesting point is that, if you read all of the claims, none of them appear to apply to the 2D analogue of Simplex noise so long as it uses a gradient generator separate from the one described in claim #1. The skew function in Claim #2 only applies to 3D, and #5 explicitly refers to n>=3.

    And none of the patent claims speak about using surflets / "spherically symmetric kernels" to generate the "images with texture that do not have visible grid artifacts," which is probably the biggest similarity between the two algorithms.

Credits

  • Kurt Spencer - Original work

  • Alex - Python port and package author

  • CreamyCookie - Cleanup and optimizations

  • Owen Raccuglia - Test cases

  • /u/redblobgames - Fixed conversion for Java's long type, see Reddit

  • PetyaVasya - Found bug with using c_long on Windows systems, see Issue #7

  • ktritz - First numba/numpy implementation, see Issue #4

  • Thomas Rometsch and MightyBOBcnc - Numba optimization tricks, see Issue #4

License

While the original work was released to the public domain by Kurt, this package is using the MIT license. Please see the file LICENSE for details.

Expected Output

Example images visualising 2D, 3D and 4D noise on a 2D plane, using the default seed:

2D noise

image

3D noise

image

4D noise

image

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

opensimplex-0.4.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

opensimplex-0.4-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file opensimplex-0.4.tar.gz.

File metadata

  • Download URL: opensimplex-0.4.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for opensimplex-0.4.tar.gz
Algorithm Hash digest
SHA256 f8dcd7bc0815d32f3dd13deada3282286ed2004f7e5daca669e7fbf98c21a2ab
MD5 624237e062a5a52046774de976960031
BLAKE2b-256 167e5f8ffb7ac7c0a624d395d5eebb927c46805b21100e5c8bf6e0d19286703a

See more details on using hashes here.

File details

Details for the file opensimplex-0.4-py3-none-any.whl.

File metadata

  • Download URL: opensimplex-0.4-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for opensimplex-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cec689ec7b259769960702a5ab318bd8e898f482bd65b1dd67854ca9c43930b3
MD5 3cfa0423d6d7f20766bf89f02a29f2b5
BLAKE2b-256 ca4edad6b719f2078f7f1f8f92977a1390f27b540edeb80f0801c14522078b67

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