particles static method
Generate random terrain using the Particle Deposition method.
Based on http://www.lighthouse3d.com/opengl/terrain/index.php?particle Repeatedly deposit particles on terrain vertices. Pick a random neighbor of that vertex. If the neighbor is lower, roll the particle to the neighbor. When the particle stops, displace the vertex upwards.
The shape of the outcome is highly dependent on options.frequency because that affects how many particles will be dropped. Values around 0.25 generally result in archipelagos whereas the default of 2.5 generally results in one large mountainous island.
Parameters are the same as those for {@link static DiamondSquare}.
Implementation
static void particles(Float32List g, TerrainOptions options) {
final iterations = math.sqrt(options.xSegments*options.xSegments + options.ySegments*options.ySegments) * options.frequency * 300;
double displacement = (options.maxHeight! - options.minHeight!) / iterations * 1000,
xDeviation = math.Random().nextDouble() * 0.2 - 0.1,
yDeviation = math.Random().nextDouble() * 0.2 - 0.1;
int i = (math.Random().nextDouble() * options.xSegments).floor(),
j = (math.Random().nextDouble() * options.ySegments).floor(),
xl = options.xSegments + 1;
for (int k = 0; k < iterations; k++) {
deposit(g, i, j, xl, displacement);
final d = math.Random().nextDouble() * math.pi * 2;
if (k % 1000 == 0) {
xDeviation = math.Random().nextDouble() * 0.2 - 0.1;
yDeviation = math.Random().nextDouble() * 0.2 - 0.1;
}
if (k % 100 == 0) {
i = (options.xSegments*(0.5+xDeviation) + math.cos(d) * math.Random().nextDouble() * options.xSegments*(0.5-xDeviation.abs())).floor();
j = (options.ySegments*(0.5+yDeviation) + math.sin(d) * math.Random().nextDouble() * options.ySegments*(0.5-yDeviation.abs())).floor();
}
}
// static Smooth(g, options, 3);
}