perlin static method

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

Generate random terrain using the Perlin Noise method.

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

Implementation

static void perlin(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) / 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.perlin(i / divisor, j / divisor) * range;
    }
  }
}