编辑:我一直在调整 Simplex 噪声构造函数上的滑块。我使用了更软的浮点数,并且看到条形的数量减少了。可能的解决方案?
{ frequency: 0.001, amplitude: 0.010, persistence: 0.50, octaves: 10 }
我正在使用单纯形噪声来生成更好的伪随机噪声。我正在尝试创建一个基本的贴图生成器,我希望使用生成的 Simplex 噪声与预定义的纹理数组相关。我正在使用从joshforisha解释的算法来选择一个缩放到数组长度的 Simplex 数。
我在这里创建了一个简化版本。在获得代码之前,您可能需要多次刷新代码,但您应该会看到重复的“非单纯形”样式行标出单纯形噪声。
我对这种情况的理解是,返回的随机数没有被映射到数组的长度,或者它跳过了太多的数字,但我不确定。
以下是如何从阵列中获得噪声选择。我省略了对其他已定义代码的引用,以使此示例尽可能简短。
var noiseGen = new FastSimplexNoise({
/** use simplex noise constructor **/
amplitude: 0.015,
frequency: 0.015,
octaves: 3,
max: text.length /** set reference to length of textures **/,
min: 0
});
/** iterate over canvas width **/
for (var i = 0; i < width; i++) {
/** iterate over canvas height **/
for (var j = 0; j < height; j++) {
/** create noise point **/
var n = noiseGen.in2D(i, j);
/** make noise a whole number for use as index look up **/
var h = parseInt(n);
/** get texture from array **/
var t = text[h];
/** paint **/
ctx.fillStyle = t.hexidec;
ctx.fillRect(i * scale, j * scale, scale, scale);
}
}