本文主要是介绍perlin.js噪声js库详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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);}
运行结果:
这篇关于perlin.js噪声js库详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!