2d noise functions
Somehow I’ve done generative art experiments for 30 years without every really understanding noise functions. I mean I’ve certainly used some but never directly, generally by incorporating someone else’s noise-derived textures or something. So here’s some notes.
Noise functions
Processing’s noise function is probably how most generative artists first encounter noise. It is straight up Perlin noise, the classic 1985 algorithm. It’s defined for any number of dimensions but let’s just focus on 2D noise for now. You give it an x, y and it gives back a random number 0-1. The key feature of Perlin noise is it’s smooth; two x, y points near each other will have a similar value. Note there’s an implicit scale in Perlin noise; is (100, 100) “near” (0, 0)? Or do you have to go as close as (10, 10) or (1, 1)? This scale factor is not very interesting but you do want to dial in a scale that has features of the size you want. Perlin noise implementations often provide other tuning like how many octaves to calculate and how much each contributes.

Perlin noise has a problem in that it’s somewhat directional; you can see horizontal and vertical artifacts in the top 4 images above. (Taken from this blog post). The bottom 4 images are similar treatments of OpenSimplex noise. Simplex noise is a different algorithm Ken Perlin made in 2001; see here for an explication. Unfortunately Simplex noise has some worry about a patent (expires January 2022!). So that’s why there’s OpenSimplex: it has similar features but was designed to be avoid the patent. (Patents on math: so stupid.) In addition to being isotropic both kinds of simplex noise are also faster to calculate.
FastNoise is really a collection of different noise functions with an emphasis on fast implementations. Includes Perlin, Simplex, and a bunch of other choices. The project is ambitiously multi-language and has several iterations as the author has supported SIMD first and then rewritten everything as FastNoise 2. Note the author Jordan Peck works on No Man’s Sky, one of the most ambitious procedurally generated videogames out there. It’s full of noise functions.
There’s a bunch of other noise functions out there too. Worley noise, Fractal noise, Gabor noise... It’s like after Perlin got an Oscar for his noise function everyone wanted their own ;-) There’s also a lot of work in making fast implementations, running on GPUs, etc. I’m getting in the weeds now so I’m just going to look at some simple things to use with Python implementations.
Python implementations
perlin-noise, a basic Python implementation of Perlin noise. Works with any number of dimensions.
OpenSimplex has a nice Python implementation with tests and everything. It defines 2d, 3d, and 4d functions.
noise, a native code implementation of Perlin noise and true Simplex noise. 1-3 dimensions for Perlin, 2-4 for Simplex. Also includes a GLSL implementation for shaders that I did not test. This code is mostly 9 years old! But there’s no reason that should matter for something this simple. Note it has no API support for setting a seed. You can override the entire random integer function though which would let you also control seeding.
pyfastnoisesimd is a SIMD optimized, parallelized implementation of FastNoise. There’s no simple API for generating a single sample; it’s designed to generate large grids of numbers all at once (very quickly).
I’m currently using OpenSimplex in my projects, mostly because it’s the first library I found. It’s easy to use and fast enough for me.
Benchmarks
I don’t really much care about speed in my applications but I was curious, so here’s some simple timeit statistics to generate a single 2d noise sample.
Constant 50000000 loops, best of 5: 0.00469 usec per loop math.random() 10000000 loops, best of 5: 0.0359 usec per loop OpenSimplex 100000 loops, best of 5: 2.34 usec per loop perlin-noise with 6 octaves 5000 loops, best of 5: 90.6 usec per loop noise.pnoise2 5000000 loops, best of 5: 0.1 usec per loop noise.snoise2 5000000 loops, best of 5: 0.0844 usec per loop
So there you have it. About 0.1 microseconds per sample for the C implementations, 2.3 for OpenSimplex (Python), 90 for Perlin (Python). To it it another way, that’s roughly 10M samples a second for the C code. For comparison pyfastnoisesimd says it’s a few nanoseconds / sample, or 200M+ samples / second.
Using noise for art
Noise functions are just random number generators; how do you make art with them? Ha, as if there were a simple answer to that question.
I did make one simple demo that a zillion people have done; making a grid of OpenSimplex noise and then visualizing the number with a short line segment rotated by the noise value. You have to fiddle the scaling to get it to look interesting. Here’s a result that looks pretty nice plotted, although drawing all ~5900 line segments took 90 minutes.

Another classic plotter use of noise is to draw “flow fields”. It’s a simple physics simulation; you drop a particle at a point and then interpret the noise value as an angle of force. Then you draw the trace of the particle as its buffeted around your grid. I’ll probably do that next, it’s a classic with a lot of interpretations.
Seeds
An aside on seeds. It’s nice to use words as seeds instead of numbers. There’s a zillion ways to do that but one easy way to turn a string into an int is zlib.crc32(seed.encode('utf-8')). Note that’s a 32 bit int; 64 would be nicer. Oddly there are precious few 64 bit checksum and hash functions, I don’t think any are installed into Python by default.
Benchmark script
#!/bin/bash TIMEIT='python3 -m timeit -p -u usec ' echo 'Constant' $TIMEIT '0.13' echo 'math.random()' $TIMEIT -s 'import random' 'random.random()' echo 'OpenSimplex' $TIMEIT -s 'from opensimplex import OpenSimplex; os = OpenSimplex()' 'os.noise2d(1.1,1.1)' echo 'perlin-noise with 6 octaves' $TIMEIT -s 'from perlin_noise import PerlinNoise; pn = PerlinNoise(octaves=6)' 'pn.noise([1.1, 1.1])' echo 'noise.pnoise2' $TIMEIT -s 'from noise import pnoise2' 'pnoise2(1.1, 1.1)' echo 'noise.snoise2' $TIMEIT -s 'from noise import snoise2' 'snoise2(1.1, 1.1)'