Skip to main content

Vectorized, pure-Python Perlin noise library

Project description

vnoise

vnoise is a pure-Python, Numpy-based, vectorized port of the noise library. It currently implements the Perlin noise functions in 1D, 2D and 3D version (noise also implements simplex noise).

Why?

vnoise was started because the original noise library is no longer supported and binaries for recent versions of Python are unavailable, making it hard to install for non-technical users. vnoise does not suffer from the same issue since it is written in pure Python.

Is vnoise slow?

For scalar input (e.g. when computing noise values one at a time), yes (~300-2000x slower depending on the conditions).

vnoise deals with this by offering a vectorized API to compute large numbers of noise values in a single call. Since is uses Numpy internally, its performance can match or exceed the original library (0.3-4x faster depending on the conditions).

Installing

$ pip install vnoise

Using vnoise

Basic example:

>>> import vnoise
>>> noise = vnoise.Noise()
>>> noise.noise1(0.5)
0.0
>>> noise.noise1(0.1)
0.09144000000000001
>>> noise.noise2(0.1, 0.3)
0.09046282464000001
>>> noise.noise3(0.1, 0.3, 0.7)
0.27788822071249925

The noiseX() functions also accept sequences as arguments:

>>> import numpy as np
>>> noise.noise2([0.1, 0.2, 0.3], np.linspace(0.5, 0.8, 10), grid_mode=True)
array([[0.0893    , 0.08919374, 0.08912713, 0.08910291, 0.08912241,
        0.08918551, 0.08929079, 0.08943552, 0.08961588, 0.08982716],
       [0.1276    , 0.126881  , 0.12643032, 0.12626645, 0.12639833,
        0.12682535, 0.12753768, 0.12851697, 0.12973738, 0.13116695],
       [0.09615   , 0.09412557, 0.09285663, 0.09239525, 0.09276657,
        0.09396889, 0.09597453, 0.09873182, 0.10216802, 0.10619312]])

With grid_mode=True (default value), a noise value is computed for every combination of the input value. In this case, the length of the first input is 3, and the length of the second input is 10. The result is an array with shape (3, 10).

If grid_mode=False, all the input must have the same length, and the result has the same shape:

>>> noise.noise2(np.linspace(0.1, 0.3, 30), np.linspace(10, 10.5, 30), grid_mode=False)
array([0.099144  , 0.12303124, 0.14685425, 0.17057388, 0.194133  ,
       0.21745892, 0.24046583, 0.26305716, 0.28512793, 0.30656706,
       0.32725957, 0.34708877, 0.36593838, 0.38369451, 0.40024759,
       0.41549419, 0.42933872, 0.44169499, 0.45248762, 0.46165335,
       0.46914216, 0.4749182 , 0.47896062, 0.48126415, 0.48183955,
       0.4807138 , 0.47793023, 0.47354831, 0.46764335, 0.460306  ])

A seed value can be specified when creating the Noise class or afterward using the seed() function:

>>> noise = vnoise.Noise(4)
>>> noise.seed(5)

License

This code is available under the MIT license, see LICENSE.

Acknowledgments

This code is based on Casey Duncan's noise library. The port was done with the help of @tatarize

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

vnoise-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

vnoise-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vnoise-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.8

File hashes

Hashes for vnoise-0.1.0.tar.gz
Algorithm Hash digest
SHA256 831b529bc0c035edaf65218ee5c0586f4e8255452af8f6ddf003d80e7bf9c038
MD5 ecb3e2146b2a682317209afe7fb94f1a
BLAKE2b-256 59aaf5109ddf1eb65bbb3382a2c4e6949d0a5725db7274efa3a750b4c29a8214

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vnoise-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.8

File hashes

Hashes for vnoise-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 520fc5fb5fff7eb0a8a0161566bbca8cdef9aa1d4fab7c499a2451ba7d3729d1
MD5 047d5101b1cc20f9559d5a193ce97aa9
BLAKE2b-256 2ef8db4e04f4466a356137eb79152f1f8562d5052e223c44f67adb796f66b07d

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