New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fractal-noise

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fractal-noise - npm Package Compare versions

Comparing version 0.9.0 to 1.0.0

4

lib/index.d.ts

@@ -5,3 +5,3 @@ export declare type Noise1Fn = (x: number) => number;

export declare type Noise4Fn = (x: number, y: number, z: number, w: number) => number;
export declare type Options = {
export interface Options {
amplitude?: number;

@@ -11,3 +11,3 @@ frequency?: number;

persistence?: number;
};
}
export declare function makeCuboid(width: number, height: number, depth: number, noise3: Noise3Fn, options?: Options): number[][];

@@ -14,0 +14,0 @@ export declare function makeCylinderSurface(circumference: number, height: number, noise3: Noise3Fn, options?: Options): number[];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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) {

@@ -15,5 +24,7 @@ if (options === void 0) { options = {}; }

var freq = frequency * Math.pow(2, octave);
value += noise3(x * freq, y * freq, z * freq) * (amplitude * Math.pow(persistence, octave));
value +=
noise3(x * freq, y * freq, z * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y][z] = value / (2 - (1 / Math.pow(2, octaves - 1)));
field[x][y][z] = value / (2 - 1 / Math.pow(2, octaves - 1));
}

@@ -39,5 +50,7 @@ }

var _b = [radius * Math.sin(rdx), radius * Math.cos(rdx)], a = _b[0], b = _b[1];
value += noise3(a * freq, b * freq, y * freq) * (amplitude * Math.pow(persistence, octave));
value +=
noise3(a * freq, b * freq, y * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y] = value / (2 - (1 / Math.pow(2, octaves - 1)));
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1));
}

@@ -58,3 +71,3 @@ }

}
field[x] = value / (2 - (1 / Math.pow(2, octaves - 1)));
field[x] = value / (2 - 1 / Math.pow(2, octaves - 1));
}

@@ -74,5 +87,7 @@ return field;

var freq = frequency * Math.pow(2, octave);
value += noise2(x * freq, y * freq) * (amplitude * Math.pow(persistence, octave));
value +=
noise2(x * freq, y * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y] = value / (2 - (1 / Math.pow(2, octaves - 1)));
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1));
}

@@ -99,5 +114,7 @@ }

var d = TWO_PI * Math.cos(rdy);
value += noise3(a * freq, b * freq, d * freq) * (amplitude * Math.pow(persistence, octave));
value +=
noise3(a * freq, b * freq, d * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y] = value / (2 - (1 / Math.pow(2, octaves - 1)));
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1));
}

@@ -108,9 +125,1 @@ }

exports.makeSphereSurface = makeSphereSurface;
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
};
}
{
"name": "fractal-noise",
"version": "0.9.0",
"version": "1.0.0",
"description": "Fractal noise library",

@@ -8,3 +8,3 @@ "main": "lib/index",

"compile": "tsc",
"test": "standardts src/**/*.ts",
"format": "prettier --parser typescript --write src/*.ts",
"watch": "tsc --watch"

@@ -27,5 +27,5 @@ },

"devDependencies": {
"standardts": "^1",
"typescript": "^2"
"prettier": "^1.18.2",
"typescript": "^3.6.4"
}
}

@@ -48,3 +48,3 @@ # Fractal Noise

##### `type Options = { amplitude?, frequency?, octaves?, persistence? }`
##### `interface Options { amplitude?; frequency?; octaves?; persistence? }`
* `amplitude?: number` – Defaults to `1.0`

@@ -55,3 +55,3 @@ * `frequency?: number` – Defaults to `1.0`

##### `makeCuboid (width, height, depth, noise3, options?): number[][]`
##### `makeCuboid(width, height, depth, noise3, options?): number[][]`

@@ -75,3 +75,3 @@ * `width: number`

##### `makeLine (length, noise1, options?): number[]`
##### `makeLine(length, noise1, options?): number[]`

@@ -84,3 +84,3 @@ * `length: number`

##### `makeRectangle (width, height, noise2, options?): number[][]`
##### `makeRectangle(width, height, noise2, options?): number[][]`

@@ -94,3 +94,3 @@ * `width: number`

##### `makeSphereSurface (circumference, options?): number[][]`
##### `makeSphereSurface(circumference, options?): number[][]`

@@ -97,0 +97,0 @@ * `circumference: number`

@@ -1,19 +0,30 @@

const TWO_PI = 2 * Math.PI
const TWO_PI = 2 * Math.PI;
export type Noise1Fn = (x: number) => number
export type Noise1Fn = (x: number) => number;
export type Noise2Fn = (x: number, y: number) => number
export type Noise2Fn = (x: number, y: number) => number;
export type Noise3Fn = (x: number, y: number, z: number) => number
export type Noise3Fn = (x: number, y: number, z: number) => number;
export type Noise4Fn = (x: number, y: number, z: number, w: number) => number
export type Noise4Fn = (x: number, y: number, z: number, w: number) => number;
export type Options = {
amplitude?: number,
frequency?: number,
octaves?: number,
persistence?: number
export interface Options {
amplitude?: number;
frequency?: number;
octaves?: number;
persistence?: number;
}
export function makeCuboid (
function processOptions(options: Options): 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
};
}
export function makeCuboid(
width: number,

@@ -25,22 +36,26 @@ height: number,

): number[][] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const field = new Array(width)
const { amplitude, frequency, octaves, persistence } = processOptions(
options
);
const field = new Array(width);
for (let x = 0; x < width; x++) {
field[x] = new Array(height)
field[x] = new Array(height);
for (let y = 0; y < height; y++) {
field[x][y] = new Array(depth)
field[x][y] = new Array(depth);
for (let z = 0; z < depth; z++) {
let value = 0.0
let value = 0.0;
for (let octave = 0; octave < octaves; octave++) {
const freq = frequency * Math.pow(2, octave)
value += noise3(x * freq, y * freq, z * freq) * (amplitude * Math.pow(persistence, octave))
const freq = frequency * Math.pow(2, octave);
value +=
noise3(x * freq, y * freq, z * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y][z] = value / (2 - (1 / Math.pow(2, octaves - 1)))
field[x][y][z] = value / (2 - 1 / Math.pow(2, octaves - 1));
}
}
}
return field
return field;
}
export function makeCylinderSurface (
export function makeCylinderSurface(
circumference: number,

@@ -51,37 +66,47 @@ height: number,

): number[] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const radius = circumference / TWO_PI
const field = new Array(circumference)
const { amplitude, frequency, octaves, persistence } = processOptions(
options
);
const radius = circumference / TWO_PI;
const field = new Array(circumference);
for (let x = 0; x < circumference; x++) {
field[x] = new Array(height)
field[x] = new Array(height);
for (let y = 0; y < height; y++) {
let value = 0.0
let value = 0.0;
for (let octave = 0; octave < octaves; octave++) {
const freq = frequency * Math.pow(2, octave)
const nx = x / circumference
const rdx = nx * TWO_PI
const [a, b] = [radius * Math.sin(rdx), radius * Math.cos(rdx)]
value += noise3(a * freq, b * freq, y * freq) * (amplitude * Math.pow(persistence, octave))
const freq = frequency * Math.pow(2, octave);
const nx = x / circumference;
const rdx = nx * TWO_PI;
const [a, b] = [radius * Math.sin(rdx), radius * Math.cos(rdx)];
value +=
noise3(a * freq, b * freq, y * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y] = value / (2 - (1 / Math.pow(2, octaves - 1)))
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1));
}
}
return field
return field;
}
export function makeLine (length: number, noise1: Noise1Fn, options: Options = {}): number[] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const field = new Array(length)
export function makeLine(
length: number,
noise1: Noise1Fn,
options: Options = {}
): number[] {
const { amplitude, frequency, octaves, persistence } = processOptions(
options
);
const field = new Array(length);
for (let x = 0; x < length; x++) {
let value = 0.0
let value = 0.0;
for (let octave = 0; octave < octaves; octave++) {
const freq = frequency * Math.pow(2, octaves)
value += noise1(x * freq) * (amplitude * Math.pow(persistence, octave))
const freq = frequency * Math.pow(2, octaves);
value += noise1(x * freq) * (amplitude * Math.pow(persistence, octave));
}
field[x] = value / (2 - (1 / Math.pow(2, octaves - 1)))
field[x] = value / (2 - 1 / Math.pow(2, octaves - 1));
}
return field
return field;
}
export function makeRectangle (
export function makeRectangle(
width: number,

@@ -92,48 +117,51 @@ height: number,

): number[] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const field = new Array(width)
const { amplitude, frequency, octaves, persistence } = processOptions(
options
);
const field = new Array(width);
for (let x = 0; x < width; x++) {
field[x] = new Array(height)
field[x] = new Array(height);
for (let y = 0; y < height; y++) {
let value = 0.0
let value = 0.0;
for (let octave = 0; octave < octaves; octave++) {
const freq = frequency * Math.pow(2, octave)
value += noise2(x * freq, y * freq) * (amplitude * Math.pow(persistence, octave))
const freq = frequency * Math.pow(2, octave);
value +=
noise2(x * freq, y * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y] = value / (2 - (1 / Math.pow(2, octaves - 1)))
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1));
}
}
return field
return field;
}
export function makeSphereSurface (circumference: number, noise3: Noise3Fn, options: Options = {}): number[] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const field = new Array(circumference)
export function makeSphereSurface(
circumference: number,
noise3: Noise3Fn,
options: Options = {}
): number[] {
const { amplitude, frequency, octaves, persistence } = processOptions(
options
);
const field = new Array(circumference);
for (let x = 0; x < circumference; x++) {
field[x] = new Array(circumference)
field[x] = new Array(circumference);
for (let y = 0; y < circumference; y++) {
let value = 0.0
let value = 0.0;
for (let octave = 0; octave < octaves; octave++) {
const freq = frequency * Math.pow(2, octave)
const [nx, ny] = [x / circumference, y / circumference]
const [rdx, rdy] = [nx * TWO_PI, ny * Math.PI]
const sinY = Math.sin(rdy + Math.PI)
const a = TWO_PI * Math.sin(rdx) * sinY
const b = TWO_PI * Math.cos(rdx) * sinY
const d = TWO_PI * Math.cos(rdy)
value += noise3(a * freq, b * freq, d * freq) * (amplitude * Math.pow(persistence, octave))
const freq = frequency * Math.pow(2, octave);
const [nx, ny] = [x / circumference, y / circumference];
const [rdx, rdy] = [nx * TWO_PI, ny * Math.PI];
const sinY = Math.sin(rdy + Math.PI);
const a = TWO_PI * Math.sin(rdx) * sinY;
const b = TWO_PI * Math.cos(rdx) * sinY;
const d = TWO_PI * Math.cos(rdy);
value +=
noise3(a * freq, b * freq, d * freq) *
(amplitude * Math.pow(persistence, octave));
}
field[x][y] = value / (2 - (1 / Math.pow(2, octaves - 1)))
field[x][y] = value / (2 - 1 / Math.pow(2, octaves - 1));
}
}
return field
return field;
}
function processOptions (options: Options): 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
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc