Talk:Perlin noise: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 21: Line 21:
:: 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). -[[User:Bearophile|bearophile]] ([[User talk:Bearophile|talk]])
:: 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). -[[User:Bearophile|bearophile]] ([[User talk:Bearophile|talk]])
::: x, y and z can be any real numbers. Notice that the noise will be zero if they are all integers, though.--[[User:Grondilu|Grondilu]] ([[User talk:Grondilu|talk]]) 18:19, 5 March 2014 (UTC)
::: x, y and z can be any real numbers. Notice that the noise will be zero if they are all integers, though.--[[User:Grondilu|Grondilu]] ([[User talk:Grondilu|talk]]) 18:19, 5 March 2014 (UTC)
::: I'm not 100% sure the result is guaranteed to be between -1 and 1. It's an interpolation from the gradients on the grid points so sometimes it can exceed, but whether or not it can is not obvious. I think it's better to cap the values with noise = min(+1, max(-1, noise)); or something like that.--[[User:Grondilu|Grondilu]] ([[User talk:Grondilu|talk]]) 18:24, 5 March 2014 (UTC)
::: I'm not 100% sure the result is guaranteed to be between -1 and 1. It's an interpolation from the gradients on the grid points so sometimes it can exceed, but whether or not it can is not obvious. So instead of putting a post-condition I think it's better to cap the output with noise = min(+1, max(-1, noise)); or something like that.--[[User:Grondilu|Grondilu]] ([[User talk:Grondilu|talk]]) 18:24, 5 March 2014 (UTC)

Revision as of 18:25, 5 March 2014

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)
x, y and z can be any real numbers. Notice that the noise will be zero if they are all integers, though.--Grondilu (talk) 18:19, 5 March 2014 (UTC)
I'm not 100% sure the result is guaranteed to be between -1 and 1. It's an interpolation from the gradients on the grid points so sometimes it can exceed, but whether or not it can is not obvious. So instead of putting a post-condition I think it's better to cap the output with noise = min(+1, max(-1, noise)); or something like that.--Grondilu (talk) 18:24, 5 March 2014 (UTC)