I am trying to port the classic Perlin Noise (src: http://mrl.nyu.edu/~perlin/doc/oscar.html#noise ) to JavaScript - for scientific purposes. I don't know why, but my code generates a periodic pattern instead of a random pattern.
You can find my full code with an example drawn on the canvas here (trimmed to one dimension): http://jsfiddle.net/YL77D/
I think the problem can be found in the function "noise1":
sx = s_curve(rx0);
u = rx0 * g1[ p[ bx0 ] ];
v = rx1 * g1[ p[ bx1 ] ];
return lerp(sx, u, v);
If my x-seed is 10.1, 10.2, 10.3, etc. I think u and v should be the same number (u should be based on 10, and v should be based on 11 - so sx is somewhere in between). I'm right? But in my code, u and v are always different.
Any ideas? Thank you very much.
source
share