PyFastNoiseSIMD Reference

class pyfastnoisesimd.CellularDistanceFunction[source]

Enum: The distance function for cellular noise.

Values: {Euclidean, Manhattan, Natural}

Euclidean = 0
Manhattan = 1
Natural = 2
class pyfastnoisesimd.CellularReturnType[source]

Enum: The functional filter to apply to the distance function to generate the return from cellular noise.

Values: {CellValue, Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div, NoiseLookup, Distance2Cave}

CellValue = 0
Distance = 1
Distance2 = 2
Distance2Add = 3
Distance2Cave = 8
Distance2Div = 6
Distance2Mul = 5
Distance2Sub = 4
NoiseLookup = 7
class pyfastnoisesimd.FractalType[source]

Enum: Fractal noise types also have an additional fractal type.

Values: {FBM, Billow, RigidMulti}

Billow = 1
FBM = 0
RigidMulti = 2
class pyfastnoisesimd.Noise(seed: int = None, numWorkers: int = None)[source]

Noise encapsulates the C++ SIMD class FNSObject and enables get/set of all relative properties via Python properties.

Parameters:
  • seed – The random number (int32) that seeds the random-number generator If seed == None a random integer is generated as the seed.
  • numWorkers – The number of threads used for parallel noise generation. If numWorkers == None, the default applied by concurrent.futures.ThreadPoolExecutor is used.
axesScales

Sets the FastNoiseSIMD axes scales, which allows for non-square voxels. Indirectly affects frequency by changing the voxel pitch.

Default: (1.0, 1.0, 1.0)

frequency

The frequency of the noise, lower values result in larger noise features.

Default: 0.01

genAsGrid(shape=[1, 1024, 1024], start=[0, 0, 0]) → numpy.ndarray[source]

Generates noise according to the set properties along a rectilinear (evenly-spaced) grid.

Parameters:
  • shape – Tuple[int] the shape of the output noise volume.
  • start – Tuple[int] the starting coordinates for generation of the grid. I.e. the coordinates are essentially start: start + shape

Example:

import numpy as np
import pyfastnoisesimd as fns
noise = fns.Noise()
result = noise.genFromGrid(shape=[256,256,256], start=[0,0,0])
nextResult = noise.genFromGrid(shape=[256,256,256], start=[256,0,0])
genFromCoords(coords: numpy.ndarray) → numpy.ndarray[source]

Generate noise from supplied coordinates, rather than a rectilinear grid. Useful for complicated shapes, such as tesselated surfaces.

Parameters:coords – 3-D coords as generated by fns.empty_coords() and filled with relevant values by the user.
Returns:a shape (N,) array of the generated noise values.
Return type:noise

Example:

import numpy as np
import pyfastnoisesimd as fns
numCoords = 256
coords = fns.empty_coords(3,numCoords)
# <Set the coordinate values, it is a (3, numCoords) array
coords[0,:] = np.linspace(-np.pi, np.pi, numCoords)
coords[1,:] = np.linspace(-1.0, 1.0, numCoords)
coords[2,:] = np.zeros(numCoords)
noise = fns.Noise()
result = noise.genFromCoords(coords)
noiseType

The class of noise.

Default: NoiseType.Simplex

numWorkers

Sets the maximum number of thread workers that will be used for generating noise. Generally should be the number of physical CPU cores on the machine.

Default: Number of virtual cores on machine.

seed

The random-number seed used for generation of noise.

Default: numpy.random.randint()

class pyfastnoisesimd.NoiseType[source]

The class of noise generated.

Enums: {Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, WhiteNoise, Cellular, Cubic, CubicFractal}

Cellular = 7
Cubic = 8
CubicFractal = 9
Perlin = 2
PerlinFractal = 3
Simplex = 4
SimplexFractal = 5
Value = 0
ValueFractal = 1
WhiteNoise = 6
class pyfastnoisesimd.PerturbType[source]

Enum: The enumerator for the class of Perturbation.

Values: {NoPeturb, Gradient, GradientFractal, Normalise, Gradient_Normalise, GradientFractal_Normalise}

Gradient = 1
GradientFractal = 2
GradientFractal_Normalise = 5
Gradient_Normalise = 4
NoPerturb = 0
Normalise = 3
pyfastnoisesimd.aligned_chunks(array, n_chunks, axis=0)[source]

An generator that divides an array into chunks that have memory addresses compatible with SIMD vector length.

Parameters:
  • array – numpy.ndarray the array to chunk
  • n_chunks – int the desired number of chunks, the returned number _may_ be less.
  • axis – int the axis to chunk on, similar to numpy axis commanes.
Returns

chunk: numpy.ndarray start: Tuple[int]

the start indices of the chunk, in the array.
pyfastnoisesimd.check_alignment(array)[source]

Verifies that an array is aligned correctly for the supported SIMD level.

Parameters:array – numpy.ndarray
Returns:bool
Return type:truth
pyfastnoisesimd.empty_aligned(shape, dtype=<class 'numpy.float32'>, n_byte=32)[source]

Provides an memory-aligned array for use with SIMD accelerated instructions. Should be used to build

Adapted from: https://github.com/hgomersall/pyFFTW/blob/master/pyfftw/utils.pxi

Parameters:
  • shape – a sequence (typically a tuple) of array axes.
  • dtype – NumPy data type of the underlying array. Note FastNoiseSIMD supports only np.float32. Seg faults may occur if this is changed.
  • n_byte – byte alignment. Should always use the pyfastnoisesimd.extension.SIMD_ALIGNMENT value or seg faults may occur.
pyfastnoisesimd.empty_coords(length, dtype=<class 'numpy.float32'>, n_byte=32)[source]
pyfastnoisesimd.full_aligned(shape, fill, dtype=<class 'numpy.float32'>, n_byte=32)[source]

As per empty_aligned, but returns an array initialized to a constant value.

Parameters:
  • shape – a sequence (typically a tuple) of array axes.
  • fill – the value to fill each array element with.
  • dtype – NumPy data type of the underlying array. Note FastNoiseSIMD supports only np.float32. Seg faults may occur if this is changed.
  • n_byte – byte alignment. Should always use the pyfastnoisesimd.extension.SIMD_ALIGNMENT value or seg faults may occur.
pyfastnoisesimd.num_virtual_cores()[source]

Detects the number of virtual cores on a system without importing multiprocessing. Borrowed from NumExpr 2.6.

pyfastnoisesimd.test(verbosity=2)[source]

Run unittest suite for pyfastnoisesimd package.

class pyfastnoisesimd.helpers.FractalClass(fns)[source]

Holds properties related to noise types that include fractal octaves.

Do not instantiate this class separately from Noise.

fractalType

The type of fractal for fractal NoiseTypes.

Default: FractalType.FBM

gain

Octave gain for all fractal noise types. Reflects the ratio of the underlying noise to that of the fractal. Values > 0.5 up-weight the fractal.

Default: 0.5
lacunarity

Octave lacunarity for all fractal noise types.

Default: 2.0

octaves

Octave count for all fractal noise types, i.e. the number of log-scaled frequency levels of noise to apply. Generally 3 is sufficient for small textures/sprites (256x256 pixels), use larger values for larger textures/sprites.

Default: 3
class pyfastnoisesimd.helpers.CellularClass(fns)[source]

Holds properties related to NoiseType.Cellular.

Do not instantiate this class separately from Noise.

distanceFunc
distanceIndices

Sets the two distance indices used for distance2X return types Default: (0, 1)

jitter

The maximum distance a cellular point can move from it’s grid position. The value is relative to the cubic cell spacing of 1.0. Setting jitter > 0.5 can generate wrapping artifacts.

Default: 0.45
lookupFrequency

Relative frequency on the cellular noise lookup return type.

Default: 0.2

noiseLookupType

Sets the type of noise used if cellular return type.

Default: NoiseType.Simplex

returnType

The return type for cellular (cubic Voronoi) noise.

Default: CellularReturnType.Distance

class pyfastnoisesimd.helpers.PerturbClass(fns)[source]

Holds properties related to the perturbation applied to noise.

Do not instantiate this class separately from Noise.

amp

The maximum distance the input position can be perturbed. The reasonable values of amp before artifacts are apparent increase with decreased frequency. The default value of 1.0 is quite high.

Default: 1.0

frequency

The relative frequency for the perturbation gradient.

Default: 0.5

gain

The octave gain for fractal perturbation types. Reflects the ratio of the underlying noise to that of the fractal. Values > 0.5 up-weight the fractal.

Default: 0.5

lacunarity

The octave lacunarity (gap-fill) for fractal perturbation types. Lacunarity increases the fineness of fractals. The appearance of graininess in fractal noise occurs when lacunarity is too high for the given frequency.

Default: 2.0

normaliseLength

The length for vectors after perturb normalising

Default: 1.0

octaves

The octave count for fractal perturbation types, i.e. the number of log-scaled frequency levels of noise to apply. Generally 3 is sufficient for small textures/sprites (256x256 pixels), use larger values for larger textures/sprites.

Default: 3

perturbType

The class of perturbation.

Default: PerturbType.NoPeturb