这是一个2D和3D Perlin噪声和简单噪声的Javascript插件。
库相当快(10M查询/秒)。但它仍然比使用着色器慢得多。例如,如果您尝试更新整个屏幕的像素值,它将是缓慢的。
怎么使用
noise.seed(Math.random());
for (var x = 0; x < canvas.width; x++) {
for (var y = 0; y < canvas.height; y++) {
// noise.simplex2 and noise.perlin2 for 2d noise
var value = noise.simplex2(x / 100, y / 100);
// ... or noise.simplex3 and noise.perlin3:
var value = noise.simplex3(x / 100, y / 100, time);
image[x][y].r = Math.abs(value) * 256;
}
}
该库提供了一个名为“噪声”的对象,具有以下属性:
- simplex2(x, y): 2D Simplex noise function
- simplex3(x, y, z): 3D Simplex noise function
- perlin2(x, y): 2D Perlin noise function
- perlin3(x, y, z): 3D Perlin noise function
- seed(val): Seed the noise functions. Only 65536 different seeds are
supported. Use a float between 0 and 1 or an integer from 1 to 65536.
Github地址:https://github.com/josephg/noisejs