perlin.js下载地址:https://download.csdn.net/download/tianseyiwan008/11022672
噪声就是给定一个输入变量,生成一个值在0~1范围内的伪随机变量的函数。在图形学中一般是输入一个坐标得到一个范围在0~1之间的变量,在利用各种颜色计算得到一些比较酷炫的效果,像火焰、云彩、地形等。
一、全局变量名——noise
相关源码:var module = global.noise = {};
二、方法
1:noise.seed(number) ——设置种子 return void
支持2^16,可以是0-1之间的小数。
2:noise.simplex2(xin, yin) —— 二维单纯形噪声
结果按比例缩放以返回间隔中的值[-1,1]。
3:noise.simplex3(xin, yin, zin) —— 三维单纯形噪声
结果按比例缩放以返回间隔中的值[-1,1]。
4:noise.perlin2(x, y) —— 二维.perlin噪声
内插
结果按比例缩放以返回间隔中的值[-1,1]。
5:noise.perlin3(x, y,z) —— 三维.perlin噪声
内插
结果按比例缩放以返回间隔中的值[-1,1]。
示例:
noise.seed(Math.random());
var re = noise.simplex2(34.4, 78.6);
printResult(re);
re = noise.simplex3(34.4, 78.6, 23.9);
printResult(re);
re = noise.perlin2(34.4, 78.6);
printResult(re);
re = noise.perlin3(34.4, 78.6, 23.9);
printResult(re);
function printResult() {
console.log(re);
}
运行结果: