open_simplex_2 Pub version GitHub stars Twitter Follow

Dart implementation of KdotJPG's OpenSimplex2 noise algorithms.

Getting started

To use this plugin, follow the installing guide.

Usage

The package currently offers two OpenSimplex 2 noise implementations:

Both of them are used in the same way. You initialize an instance with a seed:

final noise = OpenSimplex2F(42);

This instance now allows you to evaluate noise. Here are some example calls:

noise.noise2(x, y);
noise.noise3Classic(x, y, z);
noise.noise3XYBeforeZ(x, y, z);
noise.noise4Classic(x, y, z, w);
noise.noise4XYBeforeZW(x, y, z, w);

Common interface

Both OpenSimplex2F and OpenSimplex2S share the same public interface. This is defined as OpenSimplex2.

This is useful e.g. when you want to toggle between the smoother and faster variant:

late OpenSimplex2 noise;

void initNoise({required bool faster}) {
  if (faster) {
    noise = OpenSimplex2F(42);
  } else {
    noise = OpenSimplex2S(42);
  }
}

Motivation

I ported the library to Dart in order to use it in my funvas animations.

If you are interested, you can view the gallery, follow on Twitter (where I regularly post animations), or view some of the example integrations I wrote :)

Here are some examples to start:

Background

To understand how the noise in OpenSimplex 2 works, see KdotJPG's Reddit post.

Implementation

The current implementation is based on the Java implementation in KdotJPG/OpenSimplex2.

I see two potential ways to improve on it:

  • Port the areagen code from the main repo.
  • Use the newer, faster implementations by K.jpg that have not yet been merged into the main repo.

Libraries

open_simplex_2