value static method

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

Generate random terrain using value noise.

The basic approach of value noise is to generate white noise at a smaller octave than the target and then interpolate to get a higher- resolution result. This is then repeated at different resolutions.

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

Implementation

static void value(Float32List g, TerrainOptions options) {
  // Set the segment length to the smallest power of 2 that is greater
  // than the number of vertices in either dimension of the plane
  int segments = MathUtils.ceilPowerOfTwo<int>(math.max(options.xSegments, options.ySegments) + 1).toInt();

  // Store the array of white noise outside of the WhiteNoise function to
  // avoid allocating a bunch of unnecessary arrays; we can just
  // overwrite old data each time WhiteNoise() is called.
  final data = new Float64List((segments+1)*(segments+1));

  // Layer white noise at different resolutions.
  final range = options.maxHeight! - options.minHeight!;
  for (int i = 2; i < 7; i++) {
    whiteNoise(g, options, math.pow(2.0, i).toDouble(), segments, range * math.pow(2, 2.4-i*1.2), data);
  }

  // White noise creates some weird artifacts; fix them.
  // static Smooth(g, options, 1);
  Terrain.clamp(g, TerrainOptions(
    maxHeight: options.maxHeight,
    minHeight: options.minHeight,
    stretch: true,
  ));
}