fractal-noise
Advanced tools
Comparing version
@@ -10,7 +10,8 @@ export declare type Noise1Fn = (x: number) => number; | ||
persistence: number; | ||
scale?: (x: number) => number; | ||
} | ||
export declare function makeCuboid(width: number, height: number, depth: number, noise3: Noise3Fn, options?: Partial<Options>): number[][]; | ||
export declare function makeCylinderSurface(circumference: number, height: number, noise3: Noise3Fn, options?: Partial<Options>): number[]; | ||
export declare function makeLine(length: number, noise1: Noise1Fn, options?: Partial<Options>): number[]; | ||
export declare function makeRectangle(width: number, height: number, noise2: Noise2Fn, options?: Partial<Options>): number[]; | ||
export declare function makeSphereSurface(circumference: number, noise3: Noise3Fn, options?: Partial<Options>): number[]; | ||
export declare function makeCuboid(width: number, height: number, depth: number, noise3: Noise3Fn, { amplitude, frequency, octaves, persistence, scale, }?: Partial<Options>): number[][]; | ||
export declare function makeCylinderSurface(circumference: number, height: number, noise3: Noise3Fn, { amplitude, frequency, octaves, persistence, scale, }?: Partial<Options>): number[]; | ||
export declare function makeLine(length: number, noise1: Noise1Fn, { amplitude, frequency, octaves, persistence, scale, }?: Partial<Options>): number[]; | ||
export declare function makeRectangle(width: number, height: number, noise2: Noise2Fn, { amplitude, frequency, octaves, persistence, scale, }?: Partial<Options>): number[]; | ||
export declare function makeSphereSurface(circumference: number, noise3: Noise3Fn, { amplitude, frequency, octaves, persistence, scale, }?: Partial<Options>): number[]; |
@@ -6,17 +6,8 @@ "use strict"; | ||
var TWO_PI = 2 * Math.PI; | ||
function processOptions(options) { | ||
return { | ||
amplitude: typeof options.amplitude === "number" ? options.amplitude : 1.0, | ||
frequency: typeof options.frequency === "number" ? options.frequency : 1.0, | ||
octaves: typeof options.octaves === "number" | ||
? Math.floor(options.octaves) | ||
: 1, | ||
persistence: typeof options.persistence === "number" | ||
? options.persistence | ||
: 0.5, | ||
}; | ||
} | ||
function makeCuboid(width, height, depth, noise3, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence; | ||
var defaultAmplitude = 1.0; | ||
var defaultFrequency = 1.0; | ||
var defaultOctaves = 1; | ||
var defaultPersistence = 0.5; | ||
function makeCuboid(width, height, depth, noise3, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.amplitude, amplitude = _c === void 0 ? defaultAmplitude : _c, _d = _b.frequency, frequency = _d === void 0 ? defaultFrequency : _d, _e = _b.octaves, octaves = _e === void 0 ? defaultOctaves : _e, _f = _b.persistence, persistence = _f === void 0 ? defaultPersistence : _f, scale = _b.scale; | ||
var field = new Array(width); | ||
@@ -35,2 +26,4 @@ for (var x = 0; x < width; x++) { | ||
field[x][y][z] = value / (2 - 1 / Math.pow(2, octaves - 1)); | ||
if (scale) | ||
field[x][y][z] = scale(field[x][y][z]); | ||
} | ||
@@ -42,5 +35,4 @@ } | ||
exports.makeCuboid = makeCuboid; | ||
function makeCylinderSurface(circumference, height, noise3, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence; | ||
function makeCylinderSurface(circumference, height, noise3, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.amplitude, amplitude = _c === void 0 ? defaultAmplitude : _c, _d = _b.frequency, frequency = _d === void 0 ? defaultFrequency : _d, _e = _b.octaves, octaves = _e === void 0 ? defaultOctaves : _e, _f = _b.persistence, persistence = _f === void 0 ? defaultPersistence : _f, scale = _b.scale; | ||
var radius = circumference / TWO_PI; | ||
@@ -56,3 +48,3 @@ var field = new Array(circumference); | ||
var rdx = nx * TWO_PI; | ||
var _b = [radius * Math.sin(rdx), radius * Math.cos(rdx)], a = _b[0], b = _b[1]; | ||
var _g = [radius * Math.sin(rdx), radius * Math.cos(rdx)], a = _g[0], b = _g[1]; | ||
value += noise3(a * freq, b * freq, y * freq) * | ||
@@ -62,2 +54,4 @@ (amplitude * Math.pow(persistence, octave)); | ||
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1)); | ||
if (scale) | ||
field[x][y] = scale(field[x][y]); | ||
} | ||
@@ -68,5 +62,4 @@ } | ||
exports.makeCylinderSurface = makeCylinderSurface; | ||
function makeLine(length, noise1, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence; | ||
function makeLine(length, noise1, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.amplitude, amplitude = _c === void 0 ? defaultAmplitude : _c, _d = _b.frequency, frequency = _d === void 0 ? defaultFrequency : _d, _e = _b.octaves, octaves = _e === void 0 ? defaultOctaves : _e, _f = _b.persistence, persistence = _f === void 0 ? defaultPersistence : _f, scale = _b.scale; | ||
var field = new Array(length); | ||
@@ -80,2 +73,4 @@ for (var x = 0; x < length; x++) { | ||
field[x] = value / (2 - 1 / Math.pow(2, octaves - 1)); | ||
if (scale) | ||
field[x] = scale(field[x]); | ||
} | ||
@@ -85,5 +80,4 @@ return field; | ||
exports.makeLine = makeLine; | ||
function makeRectangle(width, height, noise2, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence; | ||
function makeRectangle(width, height, noise2, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.amplitude, amplitude = _c === void 0 ? defaultAmplitude : _c, _d = _b.frequency, frequency = _d === void 0 ? defaultFrequency : _d, _e = _b.octaves, octaves = _e === void 0 ? defaultOctaves : _e, _f = _b.persistence, persistence = _f === void 0 ? defaultPersistence : _f, scale = _b.scale; | ||
var field = new Array(width); | ||
@@ -100,2 +94,4 @@ for (var x = 0; x < width; x++) { | ||
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1)); | ||
if (scale) | ||
field[x][y] = scale(field[x][y]); | ||
} | ||
@@ -106,5 +102,4 @@ } | ||
exports.makeRectangle = makeRectangle; | ||
function makeSphereSurface(circumference, noise3, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence; | ||
function makeSphereSurface(circumference, noise3, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.amplitude, amplitude = _c === void 0 ? defaultAmplitude : _c, _d = _b.frequency, frequency = _d === void 0 ? defaultFrequency : _d, _e = _b.octaves, octaves = _e === void 0 ? defaultOctaves : _e, _f = _b.persistence, persistence = _f === void 0 ? defaultPersistence : _f, scale = _b.scale; | ||
var field = new Array(circumference); | ||
@@ -115,4 +110,4 @@ for (var x = 0; x < circumference; x++) { | ||
for (var y = 0; y < circumferenceSemi; y++) { | ||
var _b = [x / circumference, y / circumferenceSemi], nx = _b[0], ny = _b[1]; | ||
var _c = [nx * TWO_PI, ny * Math.PI], rdx = _c[0], rdy = _c[1]; | ||
var _g = [x / circumference, y / circumferenceSemi], nx = _g[0], ny = _g[1]; | ||
var _h = [nx * TWO_PI, ny * Math.PI], rdx = _h[0], rdy = _h[1]; | ||
var sinY = Math.sin(rdy + Math.PI); | ||
@@ -129,2 +124,4 @@ var a = TWO_PI * Math.sin(rdx) * sinY; | ||
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1)); | ||
if (scale) | ||
field[x][y] = scale(field[x][y]); | ||
} | ||
@@ -131,0 +128,0 @@ } |
{ | ||
"name": "fractal-noise", | ||
"version": "2.0.0", | ||
"version": "2.1.0-pre1", | ||
"description": "Fractal noise library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12940
8.5%140
2.19%2
100%