Talk:Perlin noise

From Rosetta Code

Correctness

The D implementation generates exactly the same outputs of the Java version. I have used the D code to generate this image (with the grayscale code visible in the D entry): http://oi62.tinypic.com/2pt9flx.jpg

Is such image correct? Isn't a correct Perlin noise image without sharp borders, like this?

http://4.bp.blogspot.com/-u4wfD21sIvU/UsI85U78XYI/AAAAAAAAAx8/NG2fEzYjTUA/s1600/perlin2.png -bearophile (talk)

Your image is not correct. The perlin noise has a range between -1 and 1, and you use this to convert it into an unsigned byte:
Gray(cast(ubyte)(p * 256))
Try this:
Gray(cast(ubyte)((p+1)/2 * 256))
Also, your image will look smoother than the example you found on blogspot.com, since this imag is made with several octaves.
--Grondilu (talk) 17:49, 5 March 2014 (UTC)
OK, I have added a post-condition and a comment in the opCall function in the D code. The image now looks smooth and nice, thank you. Do you also want to tell me what's the pre-condition of the "noise(double x, double y, double z)" Java method (this means, what's the allowed input range for those arguments x y z)? (Generally the more semantics you put in the code, then less likely is for people like me to use it wrongly). -bearophile (talk)