Index: binaries/data/mods/public/maps/random/rmgen/painter/PerlinPainter.js =================================================================== --- /dev/null +++ binaries/data/mods/public/maps/random/rmgen/painter/PerlinPainter.js @@ -0,0 +1,44 @@ +/** + * Perlin noise painter. + * @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. + * @param {boolean} type - ELEVATION_MODIFY or ELEVATION_SET. + * @param {number} verticalScale - Vertical scale of the values height. + * @param {number} positive - If true height will be posititve, if false can be both. + * @param {number} baseHeight - Initial height if type == ELEVATION_SET. + */ +class PerlinPainter +{ + constructor(iterations = 3, scale = 5, multiplier = 0.75, type = ELEVATION_MODIFY, verticalScale = 1, positive = true, baseHeight = 0) + { + this.iterations = iterations; + this.scale = scale; + this.multiplier = multiplier; + this.type = type; + this.positive = positive; + this.verticalScale = verticalScale; + this.positive = positive; + this.baseHeight = baseHeight; + } + + paint(area) + { + for (let point of area.getPoints()) + { + let height = perlinNoise(point, this.iterations, this.scale, this.multiplier); + + if (this.positive) + height = height / 2 + 0.5; + + height *= this.verticalScale; + + if (this.type == ELEVATION_SET) + height += this.baseHeight; + else + height += g_Map.getHeight(point); + + g_Map.setHeight(point, height); + } + } +}