mountain-generator
Version:
A package for generating svg mountains.
22 lines (21 loc) • 945 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function default_1(height, points, displacement, roughness) {
const pointsArray = [];
//left point
pointsArray[0] = height / 2 + Math.random() * displacement * 2 - displacement;
//right point
pointsArray[points] = height / 2 + Math.random() * displacement * 2 - displacement;
displacement *= roughness;
//loop through segments
for (let index = 1; index < points; index *= 2) {
//find center point of segment
for (let point = points / index / 2; point < points; point += points / index) {
pointsArray[point] = (pointsArray[point - points / index / 2] + pointsArray[point + points / index / 2]) / 2;
pointsArray[point] += Math.random() * displacement * 2 - displacement;
}
displacement *= roughness;
}
return pointsArray;
}
exports.default = default_1;