weierstrass static method
Generate random terrain using Weierstrass functions.
Weierstrass functions are known for being continuous but not differentiable anywhere. This produces some nice shapes that look terrain-like, but can look repetitive from above.
Parameters are the same as those for {@link static DiamondSquare}.
Implementation
static void weierstrass(Float32List g, TerrainOptions options) {
double range = (options.maxHeight! - options.minHeight!) * 0.5,
dir1 = math.Random().nextDouble() < 0.5 ? 1 : -1,
dir2 = math.Random().nextDouble() < 0.5 ? 1 : -1,
r11 = 0.5 + math.Random().nextDouble() * 1.0,
r12 = 0.5 + math.Random().nextDouble() * 1.0,
r13 = 0.025 + math.Random().nextDouble() * 0.10,
r14 = -1.0 + math.Random().nextDouble() * 2.0,
r21 = 0.5 + math.Random().nextDouble() * 1.0,
r22 = 0.5 + math.Random().nextDouble() * 1.0,
r23 = 0.025 + math.Random().nextDouble() * 0.10,
r24 = -1.0 + math.Random().nextDouble() * 2.0;
for (int i = 0, xl = options.xSegments + 1; i < xl; i++) {
for (int j = 0, yl = options.ySegments + 1; j < yl; j++) {
double sum = 0;
for (int k = 0; k < 20; k++) {
double x = math.pow(1+r11, -k) * math.sin(math.pow(1+r12, k) * (i + 0.25*math.cos(j) + r14*j) * r13);
double y = math.pow(1+r21, -k) * math.sin(math.pow(1+r22, k) * (j + 0.25*math.cos(i) + r24*i) * r23);
sum -= math.exp(dir1*x*x + dir2*y*y);
}
g[j * xl + i] += sum * range;
}
}
Terrain.clamp(g, options);
}