simplex static method

void simplex(
  1. Float32List g,
  2. TerrainOptions options
)

Generate random terrain using the Simplex Noise method.

Parameters are the same as those for {@link static DiamondSquare}.

See https://github.com/mrdoob/three.js/blob/master/examples/webgl_terrain_dynamic.html for an interesting comparison where the generation happens in GLSL.

Implementation

static void simplex(Float32List g, TerrainOptions options) {
  Noise.seed(math.Random().nextDouble());
  final range = (options.maxHeight! - options.minHeight!) * 0.5,
        divisor = (math.min(options.xSegments, options.ySegments) + 1) * 2 / options.frequency;
  for (int i = 0, xl = options.xSegments + 1; i < xl; i++) {
    for (int j = 0, yl = options.ySegments + 1; j < yl; j++) {
      g[j * xl + i] += Noise.simplex(i / divisor, j / divisor) * range;
    }
  }
}