Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/perlinNoise.js
- This file was added.
/** | |||||
* Perlin noise. | |||||
* @param {object} point - Vector2d instance. | |||||
* @param {number} iterations - Must be > 0. The higher the more detailed the noise. | |||||
* @param {number} scale - A value > 1 zooms in and < 1 zooms out the noise. | |||||
* @param {number} multiplier - Range (0,1). Frequency reduction after each iteration. | |||||
* @return {number} - Range [-1,1]. | |||||
*/ | |||||
function perlinNoise(point, iterations = 3, scale = 5, multiplier = 0.75) | |||||
{ | |||||
if (iterations <= 0) | |||||
return 0; | |||||
Silier: iterations <= 0 :) | |||||
let value = 0; | |||||
let frequency = 1 / scale; | |||||
let weight = 1; | |||||
let weightAccumulator = 0; | |||||
for (let i = 0; i < iterations; ++i) | |||||
{ | |||||
value += weight * valueNoise2d(point.x * frequency, point.y * frequency); | |||||
lyvUnsubmitted Not Done Inline ActionsThis is really not perlin noise now. Perlin noise implies gradient noise. I suggest renaming this function. Or use the perlin noise implementation in Noise2D. lyv: This is really not perlin noise now. Perlin noise implies gradient noise.
I suggest renaming… | |||||
naniAuthorUnsubmitted Done Inline ActionsSuggestion ? Factal noise, fbm ? nani: Suggestion ? Factal noise, fbm ? | |||||
lyvUnsubmitted Not Done Inline ActionsFractal noise sounds better. lyv: Fractal noise sounds better. | |||||
weightAccumulator += weight; | |||||
frequency /= multiplier; | |||||
weight *= multiplier; | |||||
} | |||||
return value / weightAccumulator; | |||||
} |
Wildfire Games · Phabricator
iterations <= 0 :)