Perlin noise: Difference between revisions

Fixed image generating code and added a post-condition
(Used a more compact hex string in the D entry)
(Fixed image generating code and added a post-condition)
Line 52:
}
 
// Generates noise in [-1.0, 1.0].
static double opCall(in double x0, in double y0, in double z0)
pure nothrow {
out(result) {
assert(result >= -1.0 && result <= 1.0);
} body {
// Find unit cube that contains point.
immutable ubyte X = cast(int)x0.floor & 0xFF,
Line 100 ⟶ 104:
foreach (immutable x; 0 .. N) {
immutable p = PerlinNoise(x / 30.0, y / 30.0, 0.1);
im[x, y] = Gray(cast(ubyte)((p + 1) / 2 * 256));
}
im.savePGM("perlin_noise.pgm");