noise

Simplex noise (like Perlin) for CircuitPython.

  • Author(s): Tod Kurt

Implementation Notes

A basic port of https://weber.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf Also see: https://github.com/stegu/perlin-noise/blob/master/src/simplexnoise1234.c

Optimised for CircuitPython/MicroPython by:

  • F2, G2, and the x2/y2 offset are pre-computed constants (no math.sqrt at startup)

  • floor() is inlined, avoiding two function calls per noise() invocation

  • dot() is inlined via _gx/_gy tuples, avoiding per-call function and attribute lookups

Also works in desktop CPython.

class noise.Grad(x, y, z)

Holder for 3D grad. Used internally by noise()

noise.dot(grad, x, y)

Compute dot product of grad against x,y. Used internally by noise()

noise.noise(xin, yin=0)

2D SimplexNoise

Parameters:
  • xin (float) – x-location in 2D noise space

  • yin (float) – y-location in 2D noise space

Return float:

noise value between -1 and 1.

noise.noise_init()

Initialize permutation arrays. Done automatically on module load