In the realm of creative coding, noise functions serve as powerful tools for emulating the randomness and organic movements observed in the natural world. Their applications are extensive, covering everything from the generation of mountains, clouds, wind patterns, and ocean swells to abstract visualizations. This versatility makes them valuable across diverse fields, including generative art and game development.

The standard noise() function built into environments like Processing generates smooth, continuous pseudo-random values, facilitating the easy creation of visually appealing random patterns. Behind the scenes, this noise() function typically employs Perlin Noise, the gradient noise algorithm developed by Ken Perlin in 1983.

Perlin Noise, Simplex Noise, and OpenSimplex Noise

Simplex Noise was introduced in 2001 by Ken Perlin, who had developed Perlin Noise back in 1983. While Simplex Noise aimed to improve upon Perlin Noise by addressing some of its shortcomings, it came with its own set of challenges, notably patent restrictions, limitations in higher dimensions, and implementation complexity.

To overcome these hurdles, Kurt Spencer developed OpenSimplex Noise as an open-source alternative. Based on the concepts of Simplex Noise, OpenSimplex Noise was developed via a clean-room implementation to avoid patent encumbrances. Crucially, OpenSimplex Noise also reduces the directional artifacts (grid-like patterns sometimes referred to as “snapping”) often visible in Perlin and Simplex noise, resulting in smoother and more natural-looking outputs.

This article will guide you through integrating OpenSimplex Noise into Processing, exploring its features and benefits by comparing it directly with the traditional Perlin Noise.

1. Perlin Noise and Its Characteristics

Perlin Noise is a groundbreaking technique that revolutionized “natural-looking random number generation” in computer graphics, achieving widespread use in both academic and commercial fields. For this contribution, Ken Perlin received an Academy Award for Technical Achievement in 2001.

The noise() function commonly found in environments like Processing is based on Perlin Noise. Unlike standard random() functions that produce discrete, unrelated values, noise() generates values that are continuous over space and time. This key characteristic makes it easy to create smooth animations and organic-looking movements.


float n = noise(x * 0.01, y * 0.01); // Example in Processing

Adjusting the input scaling, as shown above, allows you to control the level of detail or “frequency” of the noise. Because Perlin Noise provides a visually convincing sense of “naturalness,” it has been employed in a vast array of applications, including landscape generation, simulating fluid motion, particle systems, and generative drawing techniques.

However, Perlin Noise also has some notable drawbacks:

  • It can exhibit noticeable artifacts (grid-like patterns) aligned with the coordinate axes.
  • Its visual quality tends to degrade in higher dimensions (3D and beyond).
  • It was formerly subject to patent restrictions (these have since expired).

2. OpenSimplex Noise

OpenSimplex Noise is an algorithm developed by Kurt Spencer in 2014. It was created specifically to address the artifact problems inherent in Perlin Noise and overcome limitations associated with Simplex Noise, aiming to produce noise that is more uniform and natural in appearance.

Its primary characteristics include:

  • Reduced Grid Artifacts: The prominent axis-aligned structures often seen in Perlin Noise are significantly reduced, leading to more visually organic patterns.
  • More Uniform Spatial Distribution: OpenSimplex Noise generally features a more evenly distributed output across space, reducing visual distortions sometimes caused by the underlying grid structure in other gradient noises.
  • Stable High-Dimensional Output: It generates smooth and aesthetically pleasing noise patterns consistently across 2D, 3D, and 4D. This makes it particularly well-suited for applications involving multi-dimensional data, like volumetric rendering, acoustic modeling, or dynamic time-based visualizations.
  • Patent-Free: The algorithm is unencumbered by patents, making it freely usable for commercial projects and allowing unrestricted modification of its source code without licensing concerns.

3. Implementation (Integrating with Processing)

The OpenSimplex Noise code is publicly available from the following GitHub repository and can be directly integrated into your projects: https://github.com/KdotJPG/OpenSimplex2/tree/master/java

3.1 Two Variants: OpenSimplex2 and OpenSimplex2S

Currently, the Java implementation (compatible with Processing) offers two variants that improve upon the original OpenSimplex: OpenSimplex2 and OpenSimplex2S.

The key difference lies in their design goals:

  • OpenSimplex2: Focuses on faster performance and simpler gradient generation.
  • OpenSimplex2S: Designed for smoother results, inheriting and enhancing the smoothing approach of the original OpenSimplex.

Here’s a comparison:

FeatureOpenSimplex2OpenSimplex2S
Noise Type“Raw” variant“Smoothed” variant
OutputSharper, higher contrastSmoother, more natural transitions
Example UsesTerrain roughness, masking effectsClouds, smoke, waves, general natural patterns
SpeedRelatively FasterRelatively Slower (but still very performant)
Design GoalPerformance & SimplicityBalance of Smoothness & Quality

The output of OpenSimplex2 can sometimes appear harsh when visualized directly, especially in 2D. For most artistic purposes and general visualization tasks in Processing, OpenSimplex2S is the recommended choice due to its smoother output.

Since Processing is a Java-based environment, incorporating this Java code is relatively straightforward. Follow the steps below.

3.2 Obtaining and Adding OpenSimplex2S

First, you need to get the OpenSimplex2S.java file. Download it directly from the repository: https://github.com/KdotJPG/OpenSimplex2/blob/master/java/OpenSimplex2S.java (Tip: On the GitHub page, click the “Raw” button, then right-click and select “Save As…” or copy the content.)

Next, copy the downloaded OpenSimplex2S.java file into your Processing sketch’s folder (the same folder that contains your main .pde file).

Finally, add this file to your sketch within the Processing IDE (Integrated Development Environment). There are two common ways:

Using “Add File…”:

  • Click the downward arrow tab icon (▼) located on the far right, just above the text editor.
  • Select “Add File…”.
  • Navigate to your sketch folder and choose the OpenSimplex2S.java file you just copied.

Creating a New Tab:

  • Click the same downward arrow tab icon (▼) and select “New Tab”.
  • Name the new tab exactly OpenSimplex2S.java (including the .java extension).
  • Paste the entire content of the OpenSimplex2S.java file you downloaded into this new tab.

(Note: Ensuring the file is correctly named with the .java extension and located within the sketch folder allows Processing to recognize, compile, and use the OpenSimplex2S class alongside your main .pde sketch code.)

3.3 Usage in Processing


long seed = 12345;

void setup() {
  size(1024, 360);
  background(255);
  noLoop();
}

void draw() {
  background(0);
  noFill();
  stroke(255);
  float xoff = 0;
  beginShape();
  for (int x = 0; x < width; x++) {
    //float y = noise(xoff) * height; //ParinNoise
    float y = map((float)OpenSimplex2S.noise2(seed, xoff, 0), -1, 1, 0, 1) * height; //OpenSimplexNoise2S
    vertex(x, y);
    xoff += 0.01;
  }
  endShape();

  line(0, height / 2, width, height / 2);
}

The example above demonstrates plotting a 1D noise graph. Since OpenSimplex2/2S does not include a specific 1D noise function (like noise1), we utilize the 2D function (noise2) here, effectively treating it as 1D by keeping the second input coordinate constant (e.g., 0).

While previous versions of OpenSimplex required instantiation (creating an object like new OpenSimplexNoise(...)), OpenSimplex2.java and OpenSimplex2S.java are designed as utility classes. This means they differ from typical classes and are intended for direct use of their static methods (e.g., OpenSimplex2S.noise2(...)) without needing to create an object instance first.

In Processing, you can retrieve the noise value directly using methods like OpenSimplex2S.noise2(seed, x, y). However, note the following:

  1. Type Casting: These methods return a double. Since Processing's drawing functions primarily use float, you usually need to cast the result to float (e.g., (float)OpenSimplex2S.noise2(...)).
  2. Value Range: The returned value is in the range [-1.0, 1.0]. If you want to use it in the [0.0, 1.0] range, similar to Processing's built-in noise() function, you must map the value using Processing's map() function: map(noiseValue, -1, 1, 0, 1).

4. Comparison: Perlin Noise vs. OpenSimplex2S

Comparison via Graphs

A visual comparison can be made by plotting graphs where the horizontal axis represents time (or an X-coordinate input offset) and the vertical axis represents the output noise value.

Parlin Noise

OpenSimplex Noise2

Comparison in 3D

For comparing in three dimensions, one could adapt the "Noise 3D" examples available on the official Processing website, applying the noise values generated by each method to the Z-coordinate of points or shapes.

Parlin Noise

OpenSimplex Noise2

4.1 Visual Differences

Perlin Noise can sometimes exhibit subtle patterns aligned with the coordinate axes. These artifacts become more noticeable, particularly with higher frequency noise (smaller scale inputs) or when zoomed in significantly.

In contrast, OpenSimplex Noise (specifically OpenSimplex2S) is designed to suppress these grid-like structures, resulting in a distribution that often feels more naturally random and less directionally biased.

4.2 Tendency for Artifacts

With Perlin Noise, the noise gradients can sometimes align locally, which may contribute to a somewhat artificial appearance in certain visualizations. OpenSimplex benefits from gradient distributions designed to be more uniform, leading to fewer noticeable visual "quirks" or directional biases. This is a key advantage.

FeaturePerlin NoiseOpenSimplex Noise (2S)
SmoothnessGoodExcellent
Grid Influence/ArtifactsNoticeable (Fair/Poor)Almost None (Excellent)
High-Dimensional SupportDegrades (Fair/Poor)Excellent
Ease of ImplementationExcellent (Built-in)Good (Requires Adding File)

4.3 Performance

Regarding rendering performance, Processing's built-in noise() function (Perlin Noise) is generally faster, often benefiting from native code optimizations within the Processing environment.

OpenSimplex, being implemented as standard Java code, typically has a slightly higher computational cost. However, its performance is generally well within acceptable limits for most practical interactive applications. For extremely demanding real-time animations that heavily rely on noise calculations every frame, the performance difference might become relevant, making it important to choose based on the specific project's needs.

4.4 Differences: Processing's Perlin noise() vs. OpenSimplex2S

FeatureProcessing's noise()OpenSimplex2S (noiseX methods)
Dimension SpecificationAuto-detected by number of args (1-3D)Explicit method name (noise2, noise3, noise4)
Seed SpecificationInternal / AutomaticRequires explicit seed (long) argument
Return Typefloatdouble (requires casting to float for Processing use)
Value Range0.0 to 1.0-1.0 to 1.0

5. Application Examples

OpenSimplex Noise is also highly effective in the following scenarios within the Processing environment:

5.1 Field Representation (Terrain/Wind)

By treating noise values as elevation or wind speed, more natural terrain generation becomes possible.


float z = 0;
void draw() {
  background(0);
  for (int x = 0; x < width; x += 10) {
    for (int y = 0; y < height; y += 10) {
      float n = (float) OpenSimplex2S.noise3_ImproveXZ(seed, x * 0.01, y * 0.01, z);
      ellipse(x, y, 10 * (n * 0.5 + 0.5), 10 * (n * 0.5 + 0.5));
    }
  }
  z += 0.01;
}

5.2 Fractal Noise (Layering Octaves)

To create more complex patterns, "fractal noise," which involves layering multiple noises at different scales, also works well with OpenSimplex.


float fractalNoise(float x, float y, int octaves, float lacunarity, float gain) {
  float sum = 0;
  float amplitude = 1;
  float frequency = 1;
  for (int i = 0; i < octaves; i++) {
    sum += (float)OpenSimplex2S.noise2(seed, x * frequency, y * frequency) * amplitude;
    amplitude *= gain;
    frequency *= lacunarity;
  }
  return sum;
}

OpenSimplex Noise

OpenSimplex Noise is a high-quality noise function that retains the natural appearance of Perlin Noise while enabling more uniform and less distorted expressions. Especially for spatial representation using noise and higher-dimensional visualizations, its smoothness and stability are significant advantages.

Since it can be easily implemented in Processing, it serves as an alternative to the built-in noise() function, greatly expanding not only visual appeal but also the novelty of patterns and the range of expression.

Recommended Book / Generative art for beginner

Generative Art: A Practical Guide Using Processing – Matt Pearson

Generative Art presents both the techniques and the beauty of algorithmic art. In it, you’ll find dozens of high-quality examples of generative art, along with the specific steps the author followed to create each unique piece using the Processing programming language. The book includes concise tutorials for each of the technical components required to create the book’s images, and it offers countless suggestions for how you can combine and reuse the various techniques to create your own works.

Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.
—–
► Generative Art: A Practical Guide Using Processing – Matt Pearson
Publication date: 2011. July

BGD_SOUNDS (barbe_generative_diary SOUNDS)

barbe_generative_diary SOUNDS will start sharing and selling a variety of field recordings collected for use in my artwork “Sound Visualization” experiments. All sounds are royalty-free.

Link / BGD_SOUNDS on bandcamp